
//-------------------------------------------------------------------------
//   Copyright 2002-2021 National Technology & Engineering Solutions of
//   Sandia, LLC (NTESS).  Under the terms of Contract DE-NA0003525 with
//   NTESS, the U.S. Government retains certain rights in this software.
//
//   This file is part of the Xyce(TM) Parallel Electrical Simulator.
//
//   Xyce(TM) is free software: you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   Xyce(TM) is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with Xyce(TM).
//   If not, see <http://www.gnu.org/licenses/>.
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
//
// Purpose        :
//
// Special Notes  : Generated from verilog file juncap200.va with ADMS
//                  interface for Xyce 7.3.0
//                  DO NOT EDIT THIS FILE DIRECTLY!  It may be overwritten!
//
// Creator        : admsXml-2.3.6
//
// Creation Date  : Sun, 18 Apr 2021 10:09:00
//
//-------------------------------------------------------------------------
// Shut up clang's warnings about extraneous parentheses
#ifdef __clang__
#  pragma clang diagnostic ignored "-Wparentheses-equality"
#endif

#include <Xyce_config.h>
#include <N_DEV_ADMSJUNCAP200.h>


#include <N_DEV_Const.h>
#include <N_DEV_DeviceOptions.h>
#include <N_DEV_DeviceMaster.h>
#include <N_DEV_ExternData.h>
#include <N_DEV_SolverState.h>
#include <N_DEV_Message.h>

#include <N_LAS_Matrix.h>
#include <N_LAS_Vector.h>

  #include <N_ANP_NoiseData.h>

#include <N_UTL_FeatureTest.h>
#include <unordered_map>
using std::unordered_map;

#include <algorithm>

// Xyce_config.h contains a VERSION macro from autoconf, and some
// Verilog-A models like to define a variable of that name.  This can be
// a serious problem, and we don't need the VERSION macro.  Get rid of it.
// This must happen *after* all includes of Xyce headers, each of which
// includes Xyce_config.h!
#ifdef VERSION
#undef VERSION
#endif

namespace Xyce {
namespace Device {
namespace ADMSJUNCAP200 {
JacobianStamp Instance::jacStamp;
IdVector Instance::nodeMap;
PairMap Instance::pairToJacStampMap;


//This is necessary because the IntPair usage can trip undefined references
    const int Instance::admsNodeID_A;
    const int Instance::admsNodeID_K;
     const int Instance::admsNodeID_GND;
   // Additional IDs for branch equations


void
Traits::loadInstanceParameters(ParametricData<ADMSJUNCAP200::Instance> &p)
{
  // Set up each parameter directly, using the up-cased variable name
  // as the tag.

  // This kludge is to force us always to have an instance parameter
  // that the device manager can set to the temperature, even if we have
  // no "TEMP".
  p.addPar("XYCEADMSINSTTEMP", 0.0, &ADMSJUNCAP200::Instance::admsInstTemp)
    .setExpressionAccess(NO_DOC)
    .setUnit(U_DEGK)
    .setCategory(CAT_TEMP)
    .setDescription("Internal-use parameter for setting device instance temperature");
  p.addPar("AB", static_cast<double>(1.0e-12), &ADMSJUNCAP200::Instance::AB)
    .setUnit(U_METER2)
    .setDescription("Junction area")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&instSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("LS", static_cast<double>(1.0e-6), &ADMSJUNCAP200::Instance::LS)
    .setUnit(U_METER2)
    .setDescription("STI-edge part of junction perimeter")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&instSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("LG", static_cast<double>(1.0e-6), &ADMSJUNCAP200::Instance::LG)
    .setUnit(U_METER2)
    .setDescription("Gate-edge part of junction perimeter")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&instSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("MULT", static_cast<double>(1.0), &ADMSJUNCAP200::Instance::MULT)
    .setUnit(U_UNKNOWN)
    .setDescription("Number of devices in parallel")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&instSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("M", static_cast<double>(1.0), &ADMSJUNCAP200::Instance::MULT)
    .setUnit(U_UNKNOWN)
    .setDescription(" Alias for MULT")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&instSens)
#endif // Xyce_ADMS_SENSITIVITIES
;


}

void Traits::loadModelParameters(ParametricData<ADMSJUNCAP200::Model> &p)
{
  // Set up each parameter directly, using the up-cased variable name
  // as the tag.

  // This kludge is to force us always to have a model parameter
  // that the device manager can set to the temperature, even if we have
  // no "TEMP".
  p.addPar("XYCEADMSMODTEMP", 0.0, &ADMSJUNCAP200::Model::admsModTemp)
    .setExpressionAccess(NO_DOC)
    .setUnit(U_DEGK)
    .setCategory(CAT_TEMP)
    .setDescription("Internal-use parameter for setting device model temperature");
  p.addPar("LEVEL", static_cast<int>(200), &ADMSJUNCAP200::Model::LEVEL)
    .setUnit(U_UNKNOWN)
    .setDescription("Model level must be 200");
  p.addPar("TYPE", static_cast<int>(1.0), &ADMSJUNCAP200::Model::TYPE)
    .setUnit(U_UNKNOWN)
    .setDescription("Type parameter, in output value 1 reflects n-type, -1 reflects p-type");
  p.addPar("DTA", static_cast<double>(0.0), &ADMSJUNCAP200::Model::DTA)
    .setUnit(U_DEGK)
    .setDescription("Temperature offset with respect to ambient temperature")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("IMAX", static_cast<double>(1000.0), &ADMSJUNCAP200::Model::IMAX)
    .setUnit(U_AMP)
    .setDescription("Maximum current up to which forward current behaves exponentially")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("TRJ", static_cast<double>(21.0), &ADMSJUNCAP200::Model::TRJ)
    .setUnit(U_DEGC)
    .setDescription("Reference temperature")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("FREV", static_cast<double>(1.0e3), &ADMSJUNCAP200::Model::FREV)
    .setUnit(U_UNKNOWN)
    .setDescription("Coefficient for reverse breakdown current limitation")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CJORBOT", static_cast<double>(1.0e-3), &ADMSJUNCAP200::Model::CJORBOT)
    .setUnit(U_FARADMM2)
    .setDescription("Zero-bias capacitance per unit-of-area of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CJORSTI", static_cast<double>(1.0e-9), &ADMSJUNCAP200::Model::CJORSTI)
    .setUnit(U_FARADMM1)
    .setDescription("Zero-bias capacitance per unit-of-length of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CJORGAT", static_cast<double>(1.0e-9), &ADMSJUNCAP200::Model::CJORGAT)
    .setUnit(U_FARADMM1)
    .setDescription("Zero-bias capacitance per unit-of-length of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("VBIRBOT", static_cast<double>(1.0), &ADMSJUNCAP200::Model::VBIRBOT)
    .setUnit(U_VOLT)
    .setDescription("Built-in voltage at the reference temperature of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("VBIRSTI", static_cast<double>(1.0), &ADMSJUNCAP200::Model::VBIRSTI)
    .setUnit(U_VOLT)
    .setDescription("Built-in voltage at the reference temperature of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("VBIRGAT", static_cast<double>(1.0), &ADMSJUNCAP200::Model::VBIRGAT)
    .setUnit(U_VOLT)
    .setDescription("Built-in voltage at the reference temperature of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("PBOT", static_cast<double>(0.5), &ADMSJUNCAP200::Model::PBOT)
    .setUnit(U_UNKNOWN)
    .setDescription("Grading coefficient of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("PSTI", static_cast<double>(0.5), &ADMSJUNCAP200::Model::PSTI)
    .setUnit(U_UNKNOWN)
    .setDescription("Grading coefficient of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("PGAT", static_cast<double>(0.5), &ADMSJUNCAP200::Model::PGAT)
    .setUnit(U_UNKNOWN)
    .setDescription("Grading coefficient of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("PHIGBOT", static_cast<double>(1.16), &ADMSJUNCAP200::Model::PHIGBOT)
    .setUnit(U_VOLT)
    .setDescription("Zero-temperature bandgap voltage of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("PHIGSTI", static_cast<double>(1.16), &ADMSJUNCAP200::Model::PHIGSTI)
    .setUnit(U_VOLT)
    .setDescription("Zero-temperature bandgap voltage of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("PHIGGAT", static_cast<double>(1.16), &ADMSJUNCAP200::Model::PHIGGAT)
    .setUnit(U_VOLT)
    .setDescription("Zero-temperature bandgap voltage of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("IDSATRBOT", static_cast<double>(1.0e-12), &ADMSJUNCAP200::Model::IDSATRBOT)
    .setUnit(U_AMPMM2)
    .setDescription("Saturation current density at the reference temperature of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("IDSATRSTI", static_cast<double>(1.0e-18), &ADMSJUNCAP200::Model::IDSATRSTI)
    .setUnit(U_AMPMM1)
    .setDescription("Saturation current density at the reference temperature of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("IDSATRGAT", static_cast<double>(1.0e-18), &ADMSJUNCAP200::Model::IDSATRGAT)
    .setUnit(U_AMPMM1)
    .setDescription("Saturation current density at the reference temperature of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CSRHBOT", static_cast<double>(1.0e2), &ADMSJUNCAP200::Model::CSRHBOT)
    .setUnit(U_AMPMM3)
    .setDescription("Shockley-Read-Hall prefactor of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CSRHSTI", static_cast<double>(1.0e-4), &ADMSJUNCAP200::Model::CSRHSTI)
    .setUnit(U_AMPMM2)
    .setDescription("Shockley-Read-Hall prefactor of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CSRHGAT", static_cast<double>(1.0e-4), &ADMSJUNCAP200::Model::CSRHGAT)
    .setUnit(U_AMPMM2)
    .setDescription("Shockley-Read-Hall prefactor of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("XJUNSTI", static_cast<double>(1.0e-7), &ADMSJUNCAP200::Model::XJUNSTI)
    .setUnit(U_METER)
    .setDescription("Junction depth of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("XJUNGAT", static_cast<double>(1.0e-7), &ADMSJUNCAP200::Model::XJUNGAT)
    .setUnit(U_METER)
    .setDescription("Junction depth of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CTATBOT", static_cast<double>(1.0e2), &ADMSJUNCAP200::Model::CTATBOT)
    .setUnit(U_AMPMM3)
    .setDescription("Trap-assisted tunneling prefactor of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CTATSTI", static_cast<double>(1.0e-4), &ADMSJUNCAP200::Model::CTATSTI)
    .setUnit(U_AMPMM2)
    .setDescription("Trap-assisted tunneling prefactor of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CTATGAT", static_cast<double>(1.0e-4), &ADMSJUNCAP200::Model::CTATGAT)
    .setUnit(U_AMPMM2)
    .setDescription("Trap-assisted tunneling prefactor of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("MEFFTATBOT", static_cast<double>(0.25), &ADMSJUNCAP200::Model::MEFFTATBOT)
    .setUnit(U_UNKNOWN)
    .setDescription("Effective mass (in units of m0) for trap-assisted tunneling of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("MEFFTATSTI", static_cast<double>(0.25), &ADMSJUNCAP200::Model::MEFFTATSTI)
    .setUnit(U_UNKNOWN)
    .setDescription("Effective mass (in units of m0) for trap-assisted tunneling of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("MEFFTATGAT", static_cast<double>(0.25), &ADMSJUNCAP200::Model::MEFFTATGAT)
    .setUnit(U_UNKNOWN)
    .setDescription("Effective mass (in units of m0) for trap-assisted tunneling of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CBBTBOT", static_cast<double>(1.0e-12), &ADMSJUNCAP200::Model::CBBTBOT)
    .setUnit(U_AMPVM3)
    .setDescription("Band-to-band tunneling prefactor of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CBBTSTI", static_cast<double>(1.0e-18), &ADMSJUNCAP200::Model::CBBTSTI)
    .setUnit(U_AMPVM3M)
    .setDescription("Band-to-band tunneling prefactor of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("CBBTGAT", static_cast<double>(1.0e-18), &ADMSJUNCAP200::Model::CBBTGAT)
    .setUnit(U_AMPVM3M)
    .setDescription("Band-to-band tunneling prefactor of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("FBBTRBOT", static_cast<double>(1.0e9), &ADMSJUNCAP200::Model::FBBTRBOT)
    .setUnit(U_VMM1)
    .setDescription("Normalization field at the reference temperature for band-to-band tunneling of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("FBBTRSTI", static_cast<double>(1.0e9), &ADMSJUNCAP200::Model::FBBTRSTI)
    .setUnit(U_VMM1)
    .setDescription("Normalization field at the reference temperature for band-to-band tunneling of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("FBBTRGAT", static_cast<double>(1.0e9), &ADMSJUNCAP200::Model::FBBTRGAT)
    .setUnit(U_VMM1)
    .setDescription("Normalization field at the reference temperature for band-to-band tunneling of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("STFBBTBOT", static_cast<double>((-1.0e-3)), &ADMSJUNCAP200::Model::STFBBTBOT)
    .setUnit(U_DEGKM1)
    .setDescription("Temperature scaling parameter for band-to-band tunneling of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("STFBBTSTI", static_cast<double>((-1.0e-3)), &ADMSJUNCAP200::Model::STFBBTSTI)
    .setUnit(U_DEGKM1)
    .setDescription("Temperature scaling parameter for band-to-band tunneling of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("STFBBTGAT", static_cast<double>((-1.0e-3)), &ADMSJUNCAP200::Model::STFBBTGAT)
    .setUnit(U_DEGKM1)
    .setDescription("Temperature scaling parameter for band-to-band tunneling of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("VBRBOT", static_cast<double>(10.0), &ADMSJUNCAP200::Model::VBRBOT)
    .setUnit(U_VOLT)
    .setDescription("Breakdown voltage of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("VBRSTI", static_cast<double>(10.0), &ADMSJUNCAP200::Model::VBRSTI)
    .setUnit(U_VOLT)
    .setDescription("Breakdown voltage of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("VBRGAT", static_cast<double>(10.0), &ADMSJUNCAP200::Model::VBRGAT)
    .setUnit(U_VOLT)
    .setDescription("Breakdown voltage of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("PBRBOT", static_cast<double>(4.0), &ADMSJUNCAP200::Model::PBRBOT)
    .setUnit(U_VOLT)
    .setDescription("Breakdown onset tuning parameter of bottom component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("PBRSTI", static_cast<double>(4.0), &ADMSJUNCAP200::Model::PBRSTI)
    .setUnit(U_VOLT)
    .setDescription("Breakdown onset tuning parameter of STI-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("PBRGAT", static_cast<double>(4.0), &ADMSJUNCAP200::Model::PBRGAT)
    .setUnit(U_VOLT)
    .setDescription("Breakdown onset tuning parameter of gate-edge component")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("SWJUNEXP", static_cast<double>(0.0), &ADMSJUNCAP200::Model::SWJUNEXP)
    .setUnit(U_UNKNOWN)
    .setDescription("Flag for JUNCAP-express; 0=full model, 1=express model")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("VJUNREF", static_cast<double>(2.5), &ADMSJUNCAP200::Model::VJUNREF)
    .setUnit(U_VOLT)
    .setDescription("Typical maximum junction voltage; usually about 2*VSUP")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;
  p.addPar("FJUNQ", static_cast<double>(0.03), &ADMSJUNCAP200::Model::FJUNQ)
    .setUnit(U_UNKNOWN)
    .setDescription("Fraction below which junction capacitance components are considered negligible")
#ifdef Xyce_ADMS_SENSITIVITIES
    .setAnalyticSensitivityAvailable(true)
    .setSensitivityFunctor(&modSens)
#endif // Xyce_ADMS_SENSITIVITIES
;

}

//-----------------------------------------------------------------------------
// Function      : Instance::processParams
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
bool Instance::processParams()
{
  // set any non-constant parameter defaults

  // copy any model variables that have associated instance variables, but
  // are only given in the model card:



  // Set any parameters that were not given and whose defaults depend on other
  // parameters:


// Now we need to check that any parameters are within their ranges as
  // specified in the verilog:

//    Parameter AB : [ 0.0,  (+inf) [
  if ( (!((AB >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter AB value " << AB << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter LS : [ 0.0,  (+inf) [
  if ( (!((LS >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter LS value " << LS << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter LG : [ 0.0,  (+inf) [
  if ( (!((LG >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter LG value " << LG << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter MULT : [ 0.0,  (+inf) [
  if ( (!((MULT >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter MULT value " << MULT << " out of range [ 0.0,  (+inf) [";
  }


  // this seems a little stupid, but verilog models that use $temperature
  // don't also use a defined parameter "Temp", and count on $temperature
  // to be the one the simulator wants:

  updateTemperature(admsInstTemp);

  // and of course, this routine is where we should put the initial_instance
  // stuff
  double I5=0.0;
  double I4=0.0;
  double I3=0.0;
  double I2=0.0;
  double I1=0.0;
  double V5=0.0;
  double V4=0.0;
  double V3=0.0;
  double V2=0.0;
  double V1=0.0;
  double FRACI=0.0;
  double FRACNB=0.0;
  double FRACNA=0.0;
  double alphaje=0.0;
  double zfrac=0.0;
  double tt2=0.0;
  double tt1=0.0;
  double tt0=0.0;
  double I5_cor=0.0;
  double I4_cor=0.0;
  double I3_cor=0.0;
  double I2_cor=0.0;
  double I1_cor=0.0;
  double mcor_rev=0.0;
  double m0_rev=0.0;
  double pmax=0.0;
  double vbigat2r=0.0;
  double vbisti2r=0.0;
  double vbibot2r=0.0;
  double pgat2=0.0;
  double psti2=0.0;
  double pbot2=0.0;
  double vbigat2=0.0;
  double vbisti2=0.0;
  double vbibot2=0.0;
  double vmaxgat=0.0;
  double vmaxsti=0.0;
  double vmaxbot=0.0;
//Begin block initial_instance
{
AB_i = ((AB>0.0)?AB:0.0);
LS_i = ((LS>0.0)?LS:0.0);
LG_i = ((LG>0.0)?LG:0.0);
MULT_i = ((MULT>0.0)?MULT:0.0);
exp_VMAX_over_phitd = 0.0;
if ((((model_.idsatbot)*AB_i)>0.0))
{
{
double value_log_0 = log((((model_.IMAX_i)/((model_.idsatbot)*AB_i))+1.0));
vmaxbot = ((model_.phitd)*value_log_0);
}
}
else
{
vmaxbot = 1.0e8;
}
if ((((model_.idsatsti)*LS_i)>0.0))
{
{
double value_log_0 = log((((model_.IMAX_i)/((model_.idsatsti)*LS_i))+1.0));
vmaxsti = ((model_.phitd)*value_log_0);
}
}
else
{
vmaxsti = 1.0e8;
}
if ((((model_.idsatgat)*LG_i)>0.0))
{
{
double value_log_0 = log((((model_.IMAX_i)/((model_.idsatgat)*LG_i))+1.0));
vmaxgat = ((model_.phitd)*value_log_0);
}
}
else
{
vmaxgat = 1.0e8;
}
{
double value_min_0 = std::min(vmaxbot,vmaxsti);
double value_min_1 = std::min(std::min(vmaxbot,vmaxsti),vmaxgat);
VMAX = std::min(std::min(vmaxbot,vmaxsti),vmaxgat);
}
if ((fabs((VMAX*(model_.phitdinv)))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((VMAX*(model_.phitdinv)));
exp_VMAX_over_phitd = value_exp_0;
}
}
else
{
if (((VMAX*(model_.phitdinv))<0.0))
{
exp_VMAX_over_phitd = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(VMAX*(model_.phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(VMAX*(model_.phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(VMAX*(model_.phitdinv)))*3.3333333333333333e-01))))))));
}
else
{
exp_VMAX_over_phitd = (1.0e100*(1.0+(((VMAX*(model_.phitdinv))-2.3025850929940458e+02)*(1.0+(0.5*(((VMAX*(model_.phitdinv))-2.3025850929940458e+02)*(1.0+(((VMAX*(model_.phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
vbibot2 = (model_.vbibot);
vbisti2 = (model_.vbisti);
vbigat2 = (model_.vbigat);
pbot2 = (model_.PBOT_i);
psti2 = (model_.PSTI_i);
pgat2 = (model_.PGAT_i);
vbibot2r = (model_.VBIRBOT_i);
vbisti2r = (model_.VBIRSTI_i);
vbigat2r = (model_.VBIRGAT_i);
if ((AB_i==0.0))
{
vbibot2 = ((model_.vbisti)+(model_.vbigat));
{
double value_min_0 = std::min((model_.PSTI_i),(model_.PGAT_i));
pbot2 = (0.9*std::min((model_.PSTI_i),(model_.PGAT_i)));
}
vbibot2r = ((model_.VBIRSTI_i)+(model_.VBIRGAT_i));
}
if ((LS_i==0.0))
{
vbisti2 = ((model_.vbibot)+(model_.vbigat));
{
double value_min_0 = std::min((model_.PBOT_i),(model_.PGAT_i));
psti2 = (0.9*std::min((model_.PBOT_i),(model_.PGAT_i)));
}
vbisti2r = ((model_.VBIRBOT_i)+(model_.VBIRGAT_i));
}
if ((LG_i==0.0))
{
vbigat2 = ((model_.vbibot)+(model_.vbisti));
{
double value_min_0 = std::min((model_.PBOT_i),(model_.PSTI_i));
pgat2 = (0.9*std::min((model_.PBOT_i),(model_.PSTI_i)));
}
vbigat2r = ((model_.VBIRBOT_i)+(model_.VBIRSTI_i));
}
{
double value_min_0 = std::min(vbibot2,vbisti2);
double value_min_1 = std::min(std::min(vbibot2,vbisti2),vbigat2);
vbimin = std::min(std::min(vbibot2,vbisti2),vbigat2);
}
vch = (vbimin*0.1);
{
double value_max_0 = std::max(pbot2,psti2);
double value_max_1 = std::max(value_max_0,pgat2);
pmax = value_max_1;
}
{
double value_pow_0 = pow(2.0,((-1.0)/pmax));
vfmin = (vbimin*(1.0-value_pow_0));
}
{
double value_min_0 = std::min(vbibot2r,vbisti2r);
double value_min_1 = std::min(std::min(vbibot2r,vbisti2r),vbigat2r);
vbbtlim = (std::min(std::min(vbibot2r,vbisti2r),vbigat2r)-5.0e-2);
}
ISATFOR1 = 0.0;
MFOR1 = 1.0;
MFOR2 = 1.0;
ISATFOR2 = 0.0;
MREV = 1.0;
ISATREV = 0.0;
m0flag = 0.0;
xhighf1 = 0.0;
expxhf1 = 0.0;
xhighf2 = 0.0;
expxhf2 = 0.0;
xhighr = 0.0;
expxhr = 0.0;
m0_rev = 0.0;
mcor_rev = 0.0;
I1_cor = 0.0;
I2_cor = 0.0;
I3_cor = 0.0;
I4_cor = 0.0;
I5_cor = 0.0;
tt0 = 0.0;
tt1 = 0.0;
tt2 = 0.0;
zfrac = 0.0;
zflagbot = 1.0;
zflagsti = 1.0;
zflaggat = 1.0;
alphaje = 0.0;
if (((model_.SWJUNEXP_i)==1.0))
//Begin block JUNCAPexpressInit
{
//Block-local variables for block JUNCAPexpressInit
double ysq=0.0;
double terfc=0.0;
double erfcpos=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double h1=0.0;
double h2=0.0;
double h2d=0.0;
double h3=0.0;
double h4=0.0;
double h5=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double idmult=0.0;
double vj=0.0;
double z=0.0;
double zinv=0.0;
double two_psistar=0.0;
double vjlim=0.0;
double vjsrh=0.0;
double vbbt=0.0;
double vav=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double tmp=0.0;
double id=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double isrh=0.0;
double vbi_minus_vjsrh=0.0;
double wsrhstep=0.0;
double dwsrh=0.0;
double wsrh=0.0;
double wdep=0.0;
double asrh=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double itat=0.0;
double btat=0.0;
double twoatatoverthreebtat=0.0;
double umaxbeforelimiting=0.0;
double umax=0.0;
double sqrtumax=0.0;
double umaxpoweronepointfive=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double wgamma=0.0;
double wtat=0.0;
double ktat=0.0;
double ltat=0.0;
double mtat=0.0;
double xerfc=0.0;
double erfctimesexpmtat=0.0;
double gammamax=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double ibbt=0.0;
double Fmaxr=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double fbreakdown=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double ijunbot=0.0;
double ijunsti=0.0;
double ijungat=0.0;
double qjunbot=0.0;
double qjunsti=0.0;
double qjungat=0.0;
//End of Block-local variables
ysq = 0.0;
terfc = 0.0;
erfcpos = 0.0;
h1 = 0.0;
h2 = 0.0;
h2d = 0.0;
h3 = 0.0;
h4 = 0.0;
h5 = 0.0;
idmult = 0.0;
vj = 0.0;
z = 0.0;
zinv = 0.0;
two_psistar = 0.0;
vjlim = 0.0;
vjsrh = 0.0;
vbbt = 0.0;
vav = 0.0;
tmp = 0.0;
id = 0.0;
isrh = 0.0;
vbi_minus_vjsrh = 0.0;
wsrhstep = 0.0;
dwsrh = 0.0;
wsrh = 0.0;
wdep = 0.0;
asrh = 0.0;
itat = 0.0;
btat = 0.0;
twoatatoverthreebtat = 0.0;
umaxbeforelimiting = 0.0;
umax = 0.0;
sqrtumax = 0.0;
umaxpoweronepointfive = 0.0;
wgamma = 0.0;
wtat = 0.0;
ktat = 0.0;
ltat = 0.0;
mtat = 0.0;
xerfc = 0.0;
erfctimesexpmtat = 0.0;
gammamax = 0.0;
ibbt = 0.0;
Fmaxr = 0.0;
fbreakdown = 0.0;
qjunbot = 0.0;
qjunsti = 0.0;
qjungat = 0.0;
FRACNA = 0.4;
FRACNB = 0.65;
FRACI = 0.8;
V1 = ((-FRACNA)*(model_.VJUNREF_i));
V2 = ((-FRACNB)*(model_.VJUNREF_i));
V3 = ((-FRACI)*(model_.VJUNREF_i));
V4 = 0.1;
V5 = 0.2;
vbbt = 0.0;
two_psistar = 0.0;
if ((!(((AB_i==0.0)&&(LS_i==0.0))&&(LG_i==0.0))))
{
h1 = ((4.0*vch)*vch);
h2 = (vch/vfmin);
h2d = (V1+(vch*h2));
h3 = (vfmin+h2d);
h4 = (vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
h5 = value_sqrt_0;
}
vj = (2.0*((V1*vfmin)/(h3+h5)));
if ((V1<VMAX))
{
if ((fabs((0.5*(V1*(model_.phitdinv))))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(V1*(model_.phitdinv))));
zinv = value_exp_0;
}
}
else
{
if (((0.5*(V1*(model_.phitdinv)))<0.0))
{
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(V1*(model_.phitdinv))))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V1*(model_.phitdinv))))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V1*(model_.phitdinv))))*3.3333333333333333e-01))))))));
}
else
{
zinv = (1.0e100*(1.0+(((0.5*(V1*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(V1*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(((0.5*(V1*(model_.phitdinv)))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
idmult = (zinv*zinv);
}
else
{
idmult = ((1.0+((V1-VMAX)*(model_.phitdinv)))*exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
z = (1.0/zinv);
if ((V1>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
two_psistar = (2.0*((model_.phitd)*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
two_psistar = ((-V1)+(2.0*((model_.phitd)*value_log_1)));
}
}
vjlim = (vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((V1-vjlim)*(V1-vjlim))+((4.0*(model_.phitd))*(model_.phitd))));
vjsrh = (0.5*((V1+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V1-vbbtlim)*(V1-vbbtlim))+((4.0*(model_.phitr))*(model_.phitr))));
vbbt = (0.5*((V1+vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V1)*(V1))+((4.0*1.0e-6)*1.0e-6)));
vav = (0.5*(V1-value_sqrt_0));
}
}
if ((AB_i==0.0))
{
ijunbot = 0.0;
qjunbot = 0.0;
}
else
{
if (((model_.one_minus_PBOT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvbot))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvbot))),(model_.one_minus_PBOT));
tmp = value_pow_0;
}
}
qjunbot = (((model_.qprefbot)*(1.0-tmp))+((model_.qpref2bot)*(V1-vj)));
id = ((model_.idsatbot)*idmult);
if ((((model_.CSRHBOT_i)==0.0)&&((model_.CTATBOT_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbibot)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PBOT_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PBOT_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRBOTinv)),(model_.PBOT_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrbot)*tmp);
asrh = ((model_.ftdbot)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHBOT_i)*(asrh*wsrh));
}
if (((model_.CTATBOT_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartbot)*((wdep*(model_.one_minus_PBOT))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatbot))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatbot)*twoatatoverthreebtat)*sqrtumax)-((model_.atatbot)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatbot)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATBOT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTBOT_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)),(model_.PBOT_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PBOT)*((((model_.VBIRBOT_i)-vbbt)*(model_.wdepnulrinvbot))/tmp));
if ((fabs(((-(model_.fbbtbot))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtbot))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtbot))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTBOT_i)*(((V1*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRBOT_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRBOT_i))))
{
if (((model_.PBRBOT_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvbot))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvbot)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRBOT_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopbot)+((vav+((model_.alphaav)*(model_.VBRBOT_i)))*(model_.slopebot)));
}
}
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LS_i==0.0))
{
ijunsti = 0.0;
qjunsti = 0.0;
}
else
{
if (((model_.one_minus_PSTI)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvsti))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvsti))),(model_.one_minus_PSTI));
tmp = value_pow_0;
}
}
qjunsti = (((model_.qprefsti)*(1.0-tmp))+((model_.qpref2sti)*(V1-vj)));
id = ((model_.idsatsti)*idmult);
if ((((model_.CSRHSTI_i)==0.0)&&((model_.CTATSTI_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbisti)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PSTI_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PSTI_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRSTIinv)),(model_.PSTI_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrsti)*tmp);
asrh = ((model_.ftdsti)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHSTI_i)*(asrh*wsrh));
}
if (((model_.CTATSTI_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartsti)*((wdep*(model_.one_minus_PSTI))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatsti))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatsti)*twoatatoverthreebtat)*sqrtumax)-((model_.atatsti)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatsti)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATSTI_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTSTI_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)),(model_.PSTI_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PSTI)*((((model_.VBIRSTI_i)-vbbt)*(model_.wdepnulrinvsti))/tmp));
if ((fabs(((-(model_.fbbtsti))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtsti))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtsti))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTSTI_i)*(((V1*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRSTI_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRSTI_i))))
{
if (((model_.PBRSTI_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvsti))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvsti)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRSTI_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopsti)+((vav+((model_.alphaav)*(model_.VBRSTI_i)))*(model_.slopesti)));
}
}
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LG_i==0.0))
{
ijungat = 0.0;
qjungat = 0.0;
}
else
{
if (((model_.one_minus_PGAT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvgat))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvgat))),(model_.one_minus_PGAT));
tmp = value_pow_0;
}
}
qjungat = (((model_.qprefgat)*(1.0-tmp))+((model_.qpref2gat)*(V1-vj)));
id = ((model_.idsatgat)*idmult);
if ((((model_.CSRHGAT_i)==0.0)&&((model_.CTATGAT_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbigat)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PGAT_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PGAT_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRGATinv)),(model_.PGAT_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrgat)*tmp);
asrh = ((model_.ftdgat)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHGAT_i)*(asrh*wsrh));
}
if (((model_.CTATGAT_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartgat)*((wdep*(model_.one_minus_PGAT))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatgat))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatgat)*twoatatoverthreebtat)*sqrtumax)-((model_.atatgat)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatgat)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATGAT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTGAT_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)),(model_.PGAT_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PGAT)*((((model_.VBIRGAT_i)-vbbt)*(model_.wdepnulrinvgat))/tmp));
if ((fabs(((-(model_.fbbtgat))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtgat))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtgat))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTGAT_i)*(((V1*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRGAT_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRGAT_i))))
{
if (((model_.PBRGAT_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvgat))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvgat)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRGAT_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopgat)+((vav+((model_.alphaav)*(model_.VBRGAT_i)))*(model_.slopegat)));
}
}
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
I1 = (((AB_i*ijunbot)+(LS_i*ijunsti))+(LG_i*ijungat));
vbbt = 0.0;
two_psistar = 0.0;
if ((!(((AB_i==0.0)&&(LS_i==0.0))&&(LG_i==0.0))))
{
h1 = ((4.0*vch)*vch);
h2 = (vch/vfmin);
h2d = (V2+(vch*h2));
h3 = (vfmin+h2d);
h4 = (vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
h5 = value_sqrt_0;
}
vj = (2.0*((V2*vfmin)/(h3+h5)));
if ((V2<VMAX))
{
if ((fabs((0.5*(V2*(model_.phitdinv))))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(V2*(model_.phitdinv))));
zinv = value_exp_0;
}
}
else
{
if (((0.5*(V2*(model_.phitdinv)))<0.0))
{
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(V2*(model_.phitdinv))))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V2*(model_.phitdinv))))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V2*(model_.phitdinv))))*3.3333333333333333e-01))))))));
}
else
{
zinv = (1.0e100*(1.0+(((0.5*(V2*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(V2*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(((0.5*(V2*(model_.phitdinv)))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
idmult = (zinv*zinv);
}
else
{
idmult = ((1.0+((V2-VMAX)*(model_.phitdinv)))*exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
z = (1.0/zinv);
if ((V2>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
two_psistar = (2.0*((model_.phitd)*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
two_psistar = ((-V2)+(2.0*((model_.phitd)*value_log_1)));
}
}
vjlim = (vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((V2-vjlim)*(V2-vjlim))+((4.0*(model_.phitd))*(model_.phitd))));
vjsrh = (0.5*((V2+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V2-vbbtlim)*(V2-vbbtlim))+((4.0*(model_.phitr))*(model_.phitr))));
vbbt = (0.5*((V2+vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V2)*(V2))+((4.0*1.0e-6)*1.0e-6)));
vav = (0.5*(V2-value_sqrt_0));
}
}
if ((AB_i==0.0))
{
ijunbot = 0.0;
qjunbot = 0.0;
}
else
{
if (((model_.one_minus_PBOT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvbot))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvbot))),(model_.one_minus_PBOT));
tmp = value_pow_0;
}
}
qjunbot = (((model_.qprefbot)*(1.0-tmp))+((model_.qpref2bot)*(V2-vj)));
id = ((model_.idsatbot)*idmult);
if ((((model_.CSRHBOT_i)==0.0)&&((model_.CTATBOT_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbibot)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PBOT_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PBOT_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRBOTinv)),(model_.PBOT_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrbot)*tmp);
asrh = ((model_.ftdbot)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHBOT_i)*(asrh*wsrh));
}
if (((model_.CTATBOT_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartbot)*((wdep*(model_.one_minus_PBOT))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatbot))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatbot)*twoatatoverthreebtat)*sqrtumax)-((model_.atatbot)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatbot)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATBOT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTBOT_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)),(model_.PBOT_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PBOT)*((((model_.VBIRBOT_i)-vbbt)*(model_.wdepnulrinvbot))/tmp));
if ((fabs(((-(model_.fbbtbot))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtbot))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtbot))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTBOT_i)*(((V2*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRBOT_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRBOT_i))))
{
if (((model_.PBRBOT_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvbot))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvbot)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRBOT_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopbot)+((vav+((model_.alphaav)*(model_.VBRBOT_i)))*(model_.slopebot)));
}
}
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LS_i==0.0))
{
ijunsti = 0.0;
qjunsti = 0.0;
}
else
{
if (((model_.one_minus_PSTI)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvsti))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvsti))),(model_.one_minus_PSTI));
tmp = value_pow_0;
}
}
qjunsti = (((model_.qprefsti)*(1.0-tmp))+((model_.qpref2sti)*(V2-vj)));
id = ((model_.idsatsti)*idmult);
if ((((model_.CSRHSTI_i)==0.0)&&((model_.CTATSTI_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbisti)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PSTI_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PSTI_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRSTIinv)),(model_.PSTI_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrsti)*tmp);
asrh = ((model_.ftdsti)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHSTI_i)*(asrh*wsrh));
}
if (((model_.CTATSTI_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartsti)*((wdep*(model_.one_minus_PSTI))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatsti))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatsti)*twoatatoverthreebtat)*sqrtumax)-((model_.atatsti)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatsti)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATSTI_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTSTI_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)),(model_.PSTI_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PSTI)*((((model_.VBIRSTI_i)-vbbt)*(model_.wdepnulrinvsti))/tmp));
if ((fabs(((-(model_.fbbtsti))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtsti))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtsti))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTSTI_i)*(((V2*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRSTI_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRSTI_i))))
{
if (((model_.PBRSTI_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvsti))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvsti)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRSTI_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopsti)+((vav+((model_.alphaav)*(model_.VBRSTI_i)))*(model_.slopesti)));
}
}
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LG_i==0.0))
{
ijungat = 0.0;
qjungat = 0.0;
}
else
{
if (((model_.one_minus_PGAT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvgat))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvgat))),(model_.one_minus_PGAT));
tmp = value_pow_0;
}
}
qjungat = (((model_.qprefgat)*(1.0-tmp))+((model_.qpref2gat)*(V2-vj)));
id = ((model_.idsatgat)*idmult);
if ((((model_.CSRHGAT_i)==0.0)&&((model_.CTATGAT_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbigat)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PGAT_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PGAT_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRGATinv)),(model_.PGAT_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrgat)*tmp);
asrh = ((model_.ftdgat)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHGAT_i)*(asrh*wsrh));
}
if (((model_.CTATGAT_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartgat)*((wdep*(model_.one_minus_PGAT))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatgat))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatgat)*twoatatoverthreebtat)*sqrtumax)-((model_.atatgat)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatgat)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATGAT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTGAT_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)),(model_.PGAT_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PGAT)*((((model_.VBIRGAT_i)-vbbt)*(model_.wdepnulrinvgat))/tmp));
if ((fabs(((-(model_.fbbtgat))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtgat))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtgat))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTGAT_i)*(((V2*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRGAT_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRGAT_i))))
{
if (((model_.PBRGAT_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvgat))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvgat)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRGAT_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopgat)+((vav+((model_.alphaav)*(model_.VBRGAT_i)))*(model_.slopegat)));
}
}
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
I2 = (((AB_i*ijunbot)+(LS_i*ijunsti))+(LG_i*ijungat));
vbbt = 0.0;
two_psistar = 0.0;
if ((!(((AB_i==0.0)&&(LS_i==0.0))&&(LG_i==0.0))))
{
h1 = ((4.0*vch)*vch);
h2 = (vch/vfmin);
h2d = (V3+(vch*h2));
h3 = (vfmin+h2d);
h4 = (vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
h5 = value_sqrt_0;
}
vj = (2.0*((V3*vfmin)/(h3+h5)));
if ((V3<VMAX))
{
if ((fabs((0.5*(V3*(model_.phitdinv))))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(V3*(model_.phitdinv))));
zinv = value_exp_0;
}
}
else
{
if (((0.5*(V3*(model_.phitdinv)))<0.0))
{
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(V3*(model_.phitdinv))))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V3*(model_.phitdinv))))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V3*(model_.phitdinv))))*3.3333333333333333e-01))))))));
}
else
{
zinv = (1.0e100*(1.0+(((0.5*(V3*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(V3*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(((0.5*(V3*(model_.phitdinv)))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
idmult = (zinv*zinv);
}
else
{
idmult = ((1.0+((V3-VMAX)*(model_.phitdinv)))*exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
z = (1.0/zinv);
if ((V3>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
two_psistar = (2.0*((model_.phitd)*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
two_psistar = ((-V3)+(2.0*((model_.phitd)*value_log_1)));
}
}
vjlim = (vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((V3-vjlim)*(V3-vjlim))+((4.0*(model_.phitd))*(model_.phitd))));
vjsrh = (0.5*((V3+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V3-vbbtlim)*(V3-vbbtlim))+((4.0*(model_.phitr))*(model_.phitr))));
vbbt = (0.5*((V3+vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V3)*(V3))+((4.0*1.0e-6)*1.0e-6)));
vav = (0.5*(V3-value_sqrt_0));
}
}
if ((AB_i==0.0))
{
ijunbot = 0.0;
qjunbot = 0.0;
}
else
{
if (((model_.one_minus_PBOT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvbot))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvbot))),(model_.one_minus_PBOT));
tmp = value_pow_0;
}
}
qjunbot = (((model_.qprefbot)*(1.0-tmp))+((model_.qpref2bot)*(V3-vj)));
id = ((model_.idsatbot)*idmult);
if ((((model_.CSRHBOT_i)==0.0)&&((model_.CTATBOT_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbibot)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PBOT_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PBOT_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRBOTinv)),(model_.PBOT_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrbot)*tmp);
asrh = ((model_.ftdbot)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHBOT_i)*(asrh*wsrh));
}
if (((model_.CTATBOT_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartbot)*((wdep*(model_.one_minus_PBOT))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatbot))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatbot)*twoatatoverthreebtat)*sqrtumax)-((model_.atatbot)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatbot)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATBOT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTBOT_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)),(model_.PBOT_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PBOT)*((((model_.VBIRBOT_i)-vbbt)*(model_.wdepnulrinvbot))/tmp));
if ((fabs(((-(model_.fbbtbot))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtbot))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtbot))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTBOT_i)*(((V3*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRBOT_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRBOT_i))))
{
if (((model_.PBRBOT_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvbot))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvbot)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRBOT_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopbot)+((vav+((model_.alphaav)*(model_.VBRBOT_i)))*(model_.slopebot)));
}
}
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LS_i==0.0))
{
ijunsti = 0.0;
qjunsti = 0.0;
}
else
{
if (((model_.one_minus_PSTI)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvsti))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvsti))),(model_.one_minus_PSTI));
tmp = value_pow_0;
}
}
qjunsti = (((model_.qprefsti)*(1.0-tmp))+((model_.qpref2sti)*(V3-vj)));
id = ((model_.idsatsti)*idmult);
if ((((model_.CSRHSTI_i)==0.0)&&((model_.CTATSTI_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbisti)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PSTI_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PSTI_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRSTIinv)),(model_.PSTI_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrsti)*tmp);
asrh = ((model_.ftdsti)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHSTI_i)*(asrh*wsrh));
}
if (((model_.CTATSTI_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartsti)*((wdep*(model_.one_minus_PSTI))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatsti))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatsti)*twoatatoverthreebtat)*sqrtumax)-((model_.atatsti)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatsti)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATSTI_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTSTI_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)),(model_.PSTI_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PSTI)*((((model_.VBIRSTI_i)-vbbt)*(model_.wdepnulrinvsti))/tmp));
if ((fabs(((-(model_.fbbtsti))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtsti))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtsti))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTSTI_i)*(((V3*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRSTI_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRSTI_i))))
{
if (((model_.PBRSTI_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvsti))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvsti)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRSTI_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopsti)+((vav+((model_.alphaav)*(model_.VBRSTI_i)))*(model_.slopesti)));
}
}
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LG_i==0.0))
{
ijungat = 0.0;
qjungat = 0.0;
}
else
{
if (((model_.one_minus_PGAT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvgat))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvgat))),(model_.one_minus_PGAT));
tmp = value_pow_0;
}
}
qjungat = (((model_.qprefgat)*(1.0-tmp))+((model_.qpref2gat)*(V3-vj)));
id = ((model_.idsatgat)*idmult);
if ((((model_.CSRHGAT_i)==0.0)&&((model_.CTATGAT_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbigat)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PGAT_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PGAT_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRGATinv)),(model_.PGAT_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrgat)*tmp);
asrh = ((model_.ftdgat)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHGAT_i)*(asrh*wsrh));
}
if (((model_.CTATGAT_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartgat)*((wdep*(model_.one_minus_PGAT))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatgat))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatgat)*twoatatoverthreebtat)*sqrtumax)-((model_.atatgat)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatgat)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATGAT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTGAT_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)),(model_.PGAT_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PGAT)*((((model_.VBIRGAT_i)-vbbt)*(model_.wdepnulrinvgat))/tmp));
if ((fabs(((-(model_.fbbtgat))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtgat))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtgat))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTGAT_i)*(((V3*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRGAT_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRGAT_i))))
{
if (((model_.PBRGAT_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvgat))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvgat)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRGAT_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopgat)+((vav+((model_.alphaav)*(model_.VBRGAT_i)))*(model_.slopegat)));
}
}
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
I3 = (((AB_i*ijunbot)+(LS_i*ijunsti))+(LG_i*ijungat));
vbbt = 0.0;
two_psistar = 0.0;
if ((!(((AB_i==0.0)&&(LS_i==0.0))&&(LG_i==0.0))))
{
h1 = ((4.0*vch)*vch);
h2 = (vch/vfmin);
h2d = (V4+(vch*h2));
h3 = (vfmin+h2d);
h4 = (vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
h5 = value_sqrt_0;
}
vj = (2.0*((V4*vfmin)/(h3+h5)));
if ((V4<VMAX))
{
if ((fabs((0.5*(V4*(model_.phitdinv))))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(V4*(model_.phitdinv))));
zinv = value_exp_0;
}
}
else
{
if (((0.5*(V4*(model_.phitdinv)))<0.0))
{
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(V4*(model_.phitdinv))))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V4*(model_.phitdinv))))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V4*(model_.phitdinv))))*3.3333333333333333e-01))))))));
}
else
{
zinv = (1.0e100*(1.0+(((0.5*(V4*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(V4*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(((0.5*(V4*(model_.phitdinv)))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
idmult = (zinv*zinv);
}
else
{
idmult = ((1.0+((V4-VMAX)*(model_.phitdinv)))*exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
z = (1.0/zinv);
if ((V4>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
two_psistar = (2.0*((model_.phitd)*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
two_psistar = ((-V4)+(2.0*((model_.phitd)*value_log_1)));
}
}
vjlim = (vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((V4-vjlim)*(V4-vjlim))+((4.0*(model_.phitd))*(model_.phitd))));
vjsrh = (0.5*((V4+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V4-vbbtlim)*(V4-vbbtlim))+((4.0*(model_.phitr))*(model_.phitr))));
vbbt = (0.5*((V4+vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V4)*(V4))+((4.0*1.0e-6)*1.0e-6)));
vav = (0.5*(V4-value_sqrt_0));
}
}
if ((AB_i==0.0))
{
ijunbot = 0.0;
qjunbot = 0.0;
}
else
{
if (((model_.one_minus_PBOT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvbot))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvbot))),(model_.one_minus_PBOT));
tmp = value_pow_0;
}
}
qjunbot = (((model_.qprefbot)*(1.0-tmp))+((model_.qpref2bot)*(V4-vj)));
id = ((model_.idsatbot)*idmult);
if ((((model_.CSRHBOT_i)==0.0)&&((model_.CTATBOT_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbibot)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PBOT_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PBOT_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRBOTinv)),(model_.PBOT_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrbot)*tmp);
asrh = ((model_.ftdbot)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHBOT_i)*(asrh*wsrh));
}
if (((model_.CTATBOT_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartbot)*((wdep*(model_.one_minus_PBOT))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatbot))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatbot)*twoatatoverthreebtat)*sqrtumax)-((model_.atatbot)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatbot)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATBOT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTBOT_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)),(model_.PBOT_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PBOT)*((((model_.VBIRBOT_i)-vbbt)*(model_.wdepnulrinvbot))/tmp));
if ((fabs(((-(model_.fbbtbot))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtbot))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtbot))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTBOT_i)*(((V4*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRBOT_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRBOT_i))))
{
if (((model_.PBRBOT_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvbot))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvbot)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRBOT_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopbot)+((vav+((model_.alphaav)*(model_.VBRBOT_i)))*(model_.slopebot)));
}
}
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LS_i==0.0))
{
ijunsti = 0.0;
qjunsti = 0.0;
}
else
{
if (((model_.one_minus_PSTI)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvsti))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvsti))),(model_.one_minus_PSTI));
tmp = value_pow_0;
}
}
qjunsti = (((model_.qprefsti)*(1.0-tmp))+((model_.qpref2sti)*(V4-vj)));
id = ((model_.idsatsti)*idmult);
if ((((model_.CSRHSTI_i)==0.0)&&((model_.CTATSTI_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbisti)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PSTI_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PSTI_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRSTIinv)),(model_.PSTI_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrsti)*tmp);
asrh = ((model_.ftdsti)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHSTI_i)*(asrh*wsrh));
}
if (((model_.CTATSTI_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartsti)*((wdep*(model_.one_minus_PSTI))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatsti))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatsti)*twoatatoverthreebtat)*sqrtumax)-((model_.atatsti)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatsti)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATSTI_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTSTI_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)),(model_.PSTI_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PSTI)*((((model_.VBIRSTI_i)-vbbt)*(model_.wdepnulrinvsti))/tmp));
if ((fabs(((-(model_.fbbtsti))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtsti))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtsti))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTSTI_i)*(((V4*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRSTI_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRSTI_i))))
{
if (((model_.PBRSTI_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvsti))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvsti)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRSTI_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopsti)+((vav+((model_.alphaav)*(model_.VBRSTI_i)))*(model_.slopesti)));
}
}
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LG_i==0.0))
{
ijungat = 0.0;
qjungat = 0.0;
}
else
{
if (((model_.one_minus_PGAT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvgat))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvgat))),(model_.one_minus_PGAT));
tmp = value_pow_0;
}
}
qjungat = (((model_.qprefgat)*(1.0-tmp))+((model_.qpref2gat)*(V4-vj)));
id = ((model_.idsatgat)*idmult);
if ((((model_.CSRHGAT_i)==0.0)&&((model_.CTATGAT_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbigat)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PGAT_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PGAT_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRGATinv)),(model_.PGAT_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrgat)*tmp);
asrh = ((model_.ftdgat)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHGAT_i)*(asrh*wsrh));
}
if (((model_.CTATGAT_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartgat)*((wdep*(model_.one_minus_PGAT))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatgat))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatgat)*twoatatoverthreebtat)*sqrtumax)-((model_.atatgat)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatgat)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATGAT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTGAT_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)),(model_.PGAT_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PGAT)*((((model_.VBIRGAT_i)-vbbt)*(model_.wdepnulrinvgat))/tmp));
if ((fabs(((-(model_.fbbtgat))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtgat))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtgat))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTGAT_i)*(((V4*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRGAT_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRGAT_i))))
{
if (((model_.PBRGAT_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvgat))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvgat)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRGAT_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopgat)+((vav+((model_.alphaav)*(model_.VBRGAT_i)))*(model_.slopegat)));
}
}
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
I4 = (((AB_i*ijunbot)+(LS_i*ijunsti))+(LG_i*ijungat));
vbbt = 0.0;
two_psistar = 0.0;
if ((!(((AB_i==0.0)&&(LS_i==0.0))&&(LG_i==0.0))))
{
h1 = ((4.0*vch)*vch);
h2 = (vch/vfmin);
h2d = (V5+(vch*h2));
h3 = (vfmin+h2d);
h4 = (vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
h5 = value_sqrt_0;
}
vj = (2.0*((V5*vfmin)/(h3+h5)));
if ((V5<VMAX))
{
if ((fabs((0.5*(V5*(model_.phitdinv))))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(V5*(model_.phitdinv))));
zinv = value_exp_0;
}
}
else
{
if (((0.5*(V5*(model_.phitdinv)))<0.0))
{
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(V5*(model_.phitdinv))))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V5*(model_.phitdinv))))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V5*(model_.phitdinv))))*3.3333333333333333e-01))))))));
}
else
{
zinv = (1.0e100*(1.0+(((0.5*(V5*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(V5*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(((0.5*(V5*(model_.phitdinv)))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
idmult = (zinv*zinv);
}
else
{
idmult = ((1.0+((V5-VMAX)*(model_.phitdinv)))*exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
z = (1.0/zinv);
if ((V5>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
two_psistar = (2.0*((model_.phitd)*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
two_psistar = ((-V5)+(2.0*((model_.phitd)*value_log_1)));
}
}
vjlim = (vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((V5-vjlim)*(V5-vjlim))+((4.0*(model_.phitd))*(model_.phitd))));
vjsrh = (0.5*((V5+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V5-vbbtlim)*(V5-vbbtlim))+((4.0*(model_.phitr))*(model_.phitr))));
vbbt = (0.5*((V5+vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V5)*(V5))+((4.0*1.0e-6)*1.0e-6)));
vav = (0.5*(V5-value_sqrt_0));
}
}
if ((AB_i==0.0))
{
ijunbot = 0.0;
qjunbot = 0.0;
}
else
{
if (((model_.one_minus_PBOT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvbot))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvbot))),(model_.one_minus_PBOT));
tmp = value_pow_0;
}
}
qjunbot = (((model_.qprefbot)*(1.0-tmp))+((model_.qpref2bot)*(V5-vj)));
id = ((model_.idsatbot)*idmult);
if ((((model_.CSRHBOT_i)==0.0)&&((model_.CTATBOT_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbibot)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PBOT_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PBOT_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRBOTinv)),(model_.PBOT_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrbot)*tmp);
asrh = ((model_.ftdbot)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHBOT_i)*(asrh*wsrh));
}
if (((model_.CTATBOT_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartbot)*((wdep*(model_.one_minus_PBOT))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatbot))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatbot)*twoatatoverthreebtat)*sqrtumax)-((model_.atatbot)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatbot)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATBOT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTBOT_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)),(model_.PBOT_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PBOT)*((((model_.VBIRBOT_i)-vbbt)*(model_.wdepnulrinvbot))/tmp));
if ((fabs(((-(model_.fbbtbot))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtbot))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtbot))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTBOT_i)*(((V5*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRBOT_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRBOT_i))))
{
if (((model_.PBRBOT_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvbot))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvbot)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRBOT_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopbot)+((vav+((model_.alphaav)*(model_.VBRBOT_i)))*(model_.slopebot)));
}
}
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LS_i==0.0))
{
ijunsti = 0.0;
qjunsti = 0.0;
}
else
{
if (((model_.one_minus_PSTI)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvsti))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvsti))),(model_.one_minus_PSTI));
tmp = value_pow_0;
}
}
qjunsti = (((model_.qprefsti)*(1.0-tmp))+((model_.qpref2sti)*(V5-vj)));
id = ((model_.idsatsti)*idmult);
if ((((model_.CSRHSTI_i)==0.0)&&((model_.CTATSTI_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbisti)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PSTI_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PSTI_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRSTIinv)),(model_.PSTI_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrsti)*tmp);
asrh = ((model_.ftdsti)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHSTI_i)*(asrh*wsrh));
}
if (((model_.CTATSTI_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartsti)*((wdep*(model_.one_minus_PSTI))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatsti))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatsti)*twoatatoverthreebtat)*sqrtumax)-((model_.atatsti)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatsti)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATSTI_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTSTI_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)),(model_.PSTI_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PSTI)*((((model_.VBIRSTI_i)-vbbt)*(model_.wdepnulrinvsti))/tmp));
if ((fabs(((-(model_.fbbtsti))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtsti))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtsti))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTSTI_i)*(((V5*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRSTI_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRSTI_i))))
{
if (((model_.PBRSTI_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvsti))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvsti)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRSTI_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopsti)+((vav+((model_.alphaav)*(model_.VBRSTI_i)))*(model_.slopesti)));
}
}
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LG_i==0.0))
{
ijungat = 0.0;
qjungat = 0.0;
}
else
{
if (((model_.one_minus_PGAT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvgat))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvgat))),(model_.one_minus_PGAT));
tmp = value_pow_0;
}
}
qjungat = (((model_.qprefgat)*(1.0-tmp))+((model_.qpref2gat)*(V5-vj)));
id = ((model_.idsatgat)*idmult);
if ((((model_.CSRHGAT_i)==0.0)&&((model_.CTATGAT_i)==0.0)))
{
isrh = 0.0;
}
else
{
vbi_minus_vjsrh = ((model_.vbigat)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PGAT_i)==0.5))
{
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PGAT_i))));
}
}
wsrh = (wsrhstep+dwsrh);
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRGATinv)),(model_.PGAT_i));
tmp = value_pow_0;
}
}
wdep = ((model_.wdepnulrgat)*tmp);
asrh = ((model_.ftdgat)*((zinv-1.0)*wdep));
isrh = ((model_.CSRHGAT_i)*(asrh*wsrh));
}
if (((model_.CTATGAT_i)==0.0))
{
itat = 0.0;
}
else
{
btat = ((model_.btatpartgat)*((wdep*(model_.one_minus_PGAT))/vbi_minus_vjsrh));
twoatatoverthreebtat = ((0.666666666666667*(model_.atatgat))/btat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
sqrtumax = value_sqrt_1;
}
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT))==(-1.0)))
{
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT)));
wgamma = value_pow_0;
}
}
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
ktat = value_sqrt_0;
}
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
mtat = (((((model_.atatgat)*twoatatoverthreebtat)*sqrtumax)-((model_.atatgat)*umax))+(0.5*(btat*umaxpoweronepointfive)));
xerfc = ((ltat-1.0)*ktat);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
tmp = value_exp_0;
}
}
else
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
gammamax = ((1.77245385090551603*0.5)*(((model_.atatgat)*erfctimesexpmtat)/ktat));
itat = ((model_.CTATGAT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTGAT_i)==0.0))
{
ibbt = 0.0;
}
else
{
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)),(model_.PGAT_i));
tmp = value_pow_0;
}
}
Fmaxr = ((model_.one_over_one_minus_PGAT)*((((model_.VBIRGAT_i)-vbbt)*(model_.wdepnulrinvgat))/tmp));
if ((fabs(((-(model_.fbbtgat))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtgat))/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtgat))/Fmaxr)<0.0))
{
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
tmp = (1.0e100*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
ibbt = ((model_.CBBTGAT_i)*(((V5*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRGAT_i)>1.0e3))
{
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRGAT_i))))
{
if (((model_.PBRGAT_i)==4.0))
{
tmp = ((((vav*(model_.VBRinvgat))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvgat)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRGAT_i));
tmp = value_pow_1;
}
}
fbreakdown = (1.0/(1.0-tmp));
}
else
{
fbreakdown = ((model_.fstopgat)+((vav+((model_.alphaav)*(model_.VBRGAT_i)))*(model_.slopegat)));
}
}
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
I5 = (((AB_i*ijunbot)+(LS_i*ijunsti))+(LG_i*ijungat));
ISATFOR1 = (((AB_i*(model_.idsatbot))+(LS_i*(model_.idsatsti)))+(LG_i*(model_.idsatgat)));
{
double value_exp_0 = exp(((V4*(model_.phitdinv))*MFOR1));
I4_cor = (I4-(ISATFOR1*(value_exp_0-1.0)));
}
{
double value_exp_0 = exp(((V5*(model_.phitdinv))*MFOR1));
I5_cor = (I5-(ISATFOR1*(value_exp_0-1.0)));
}
if ((!(((AB_i==0.0)&&(LS_i==0.0))&&(LG_i==0.0))))
{
if (((I4>0.0)&&(I5>0.0)))
{
if ((((((I4_cor/I4)>1.0e-3)||((I5_cor/I5)>1.0e-3))&&(I4_cor>0.0))&&(I5_cor>0.0)))
{
alphaje = (I4_cor/I5_cor);
{
double value_log_0 = log(alphaje);
MFOR2 = (((model_.phitd)*value_log_0)/(V4-V5));
}
{
double value_exp_0 = exp(((V4*(model_.phitdinv))*MFOR2));
ISATFOR2 = (I4_cor/(value_exp_0-1.0));
}
}
}
{
double value_exp_0 = exp(((V1*(model_.phitdinv))*MFOR1));
double value_exp_1 = exp(((V1*(model_.phitdinv))*MFOR2));
I1_cor = ((I1-(ISATFOR1*(value_exp_0-1.0)))-(ISATFOR2*(value_exp_1-1.0)));
}
{
double value_exp_0 = exp(((V2*(model_.phitdinv))*MFOR1));
double value_exp_1 = exp(((V2*(model_.phitdinv))*MFOR2));
I2_cor = ((I2-(ISATFOR1*(value_exp_0-1.0)))-(ISATFOR2*(value_exp_1-1.0)));
}
{
double value_exp_0 = exp(((V3*(model_.phitdinv))*MFOR1));
double value_exp_1 = exp(((V3*(model_.phitdinv))*MFOR2));
I3_cor = ((I3-(ISATFOR1*(value_exp_0-1.0)))-(ISATFOR2*(value_exp_1-1.0)));
}
if ((((I1<0.0)&&(I2<0.0))&&(I3<0.0)))
{
if ((((((((I1_cor/I1)>1.0e-3)||((I2_cor/I2)>1.0e-3))||((I3_cor/I3)>1.0e-3))&&(I1_cor<0.0))&&(I2_cor<0.0))&&(I3_cor<0.0)))
{
alphaje = (I1_cor/I2_cor);
{
double value_log_0 = log(alphaje);
m0_rev = (((-(model_.phitd))*value_log_0)/(V1-V2));
}
tt0 = (V2/(V2-V1));
{
double value_pow_0 = pow(alphaje,tt0);
tt1 = (((model_.phitd)*(alphaje-1.0))*(value_pow_0-1.0));
}
tt0 = (V1/(V1-V2));
{
double value_pow_0 = pow(alphaje,tt0);
tt2 = (((value_pow_0*(V2-V1))+(alphaje*V1))-V2);
}
mcor_rev = (tt1/tt2);
MREV = (m0_rev+mcor_rev);
if ((fabs(((V3*(model_.phitdinv))*MREV))<1.0e-6))
{
m0flag = 1.0;
ISATREV = (I3_cor*((1.0/V3)+((0.5*(model_.phitdinv))*MREV)));
MREV = (((((-0.5)*I3_cor)*MREV)*(model_.phitdinv))/V3);
}
else
{
m0flag = 0.0;
{
double value_exp_0 = exp((((-V3)*(model_.phitdinv))*MREV));
ISATREV = ((-I3_cor)/(value_exp_0-1.0));
}
}
}
}
}
zfrac = ((model_.FJUNQ_i)*(((AB_i*(model_.cjobot))+(LS_i*(model_.cjosti)))+(LG_i*(model_.cjogat))));
if (((AB_i*(model_.cjobot))<=zfrac))
{
zflagbot = 0.0;
}
if (((LS_i*(model_.cjosti))<=zfrac))
{
zflagsti = 0.0;
}
if (((LG_i*(model_.cjogat))<=zfrac))
{
zflaggat = 0.0;
}
if ((!(((AB_i==0.0)&&(LS_i==0.0))&&(LG_i==0.0))))
{
{
double value_log_0 = log(((0.5*(model_.IMAX_i))/(ISATFOR1+1.0e-21)));
xhighf1 = value_log_0;
}
{
double value_log_0 = log(((0.5*(model_.IMAX_i))/(ISATFOR2+1.0e-21)));
xhighf2 = value_log_0;
}
{
double value_fabs_0 = fabs(ISATREV);
double value_log_1 = log(((0.5*(model_.IMAX_i))/(value_fabs_0+1.0e-21)));
xhighr = value_log_1;
}
}
{
double value_min_0 = std::min(xhighf1,static_cast<double>(2.3025850929940458e+02));
xhighf1 = std::min(xhighf1,static_cast<double>(2.3025850929940458e+02));
}
{
double value_exp_0 = exp(xhighf1);
expxhf1 = value_exp_0;
}
{
double value_min_0 = std::min(xhighf2,static_cast<double>(2.3025850929940458e+02));
xhighf2 = std::min(xhighf2,static_cast<double>(2.3025850929940458e+02));
}
{
double value_exp_0 = exp(xhighf2);
expxhf2 = value_exp_0;
}
{
double value_min_0 = std::min(xhighr,static_cast<double>(2.3025850929940458e+02));
xhighr = std::min(xhighr,static_cast<double>(2.3025850929940458e+02));
}
{
double value_exp_0 = exp(xhighr);
expxhr = value_exp_0;
}
}
// End block JUNCAPexpressInit
}
// End block initial_instance


  return true;
}

//-----------------------------------------------------------------------------
// Function      : Instance::Instance
// Purpose       : "instance block" constructor
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------

Instance::Instance(
  const Configuration & configuration,
  const InstanceBlock & instance_block,
  Model &               model,
  const FactoryBlock &  factory_block)
  : DeviceInstance(instance_block, configuration.getInstanceParameters(), factory_block),
    model_(model),
    AB(1.0e-12),
    LS(1.0e-6),
    LG(1.0e-6),
    MULT(1.0),
    MULT_i(0.0),
    AB_i(0.0),
    LS_i(0.0),
    LG_i(0.0),
    zflagbot(0.0),
    zflagsti(0.0),
    zflaggat(0.0),
    VMAX(0.0),
    exp_VMAX_over_phitd(0.0),
    vbimin(0.0),
    vch(0.0),
    vfmin(0.0),
    vbbtlim(0.0),
    xhighf1(0.0),
    expxhf1(0.0),
    xhighf2(0.0),
    expxhf2(0.0),
    xhighr(0.0),
    expxhr(0.0),
    ISATFOR1(0.0),
    MFOR1(0.0),
    ISATFOR2(0.0),
    MFOR2(0.0),
    ISATREV(0.0),
    MREV(0.0),
    m0flag(0.0),
    vak(0.0),
    cj(0.0),
    cjbot(0.0),
    cjgat(0.0),
    cjsti(0.0),
    ij(0.0),
    ijbot(0.0),
    ijgat(0.0),
    ijsti(0.0),
    si(0.0),
    idsatsbot(0.0),
    idsatssti(0.0),
    idsatsgat(0.0),
    cjosbot(0.0),
    cjossti(0.0),
    cjosgat(0.0),
    vbisbot(0.0),
    vbissti(0.0),
    vbisgat(0.0),
    li_A(-1),
    li_K(-1),
    li_branch_iA(-1),
    f_A_Equ_A_Node_Ptr(0),
    f_A_Equ_K_Node_Ptr(0),
    f_K_Equ_A_Node_Ptr(0),
    f_K_Equ_K_Node_Ptr(0),
    q_A_Equ_A_Node_Ptr(0),
    q_A_Equ_K_Node_Ptr(0),
    q_K_Equ_A_Node_Ptr(0),
    q_K_Equ_K_Node_Ptr(0),
    A_A_Equ_A_NodeOffset(-1),
    A_A_Equ_K_NodeOffset(-1),
    A_K_Equ_A_NodeOffset(-1),
    A_K_Equ_K_NodeOffset(-1),
    li_store_vak(-1),
    li_store_cj(-1),
    li_store_cjbot(-1),
    li_store_cjgat(-1),
    li_store_cjsti(-1),
    li_store_ij(-1),
    li_store_ijbot(-1),
    li_store_ijgat(-1),
    li_store_ijsti(-1),
    li_store_si(-1),
    li_store_idsatsbot(-1),
    li_store_idsatssti(-1),
    li_store_idsatsgat(-1),
    li_store_cjosbot(-1),
    li_store_cjossti(-1),
    li_store_cjosgat(-1),
    li_store_vbisbot(-1),
    li_store_vbissti(-1),
    li_store_vbisgat(-1),
    admsTemperature(getDeviceOptions().temp.getImmutableValue<double>())

{
    numIntVars = 0 + 0;
    numExtVars = 2;

  // Right now, we only have store for limited probes and output vars...
  setNumStoreVars(0+19);

  // Do not allocate "branch" (lead current) vectors by default
  setNumBranchDataVars(0);
  numBranchDataVarsIfAllocated = 1;

  leadCurrentF.resize(2);
  leadCurrentQ.resize(2);

  // Set up jacobian stamp:
  // Create a vector of the non-zero elements of the stamp
PairVector jacobianElements;
    jacobianElements.push_back(IntPair(admsNodeID_A,admsNodeID_A));
    jacobianElements.push_back(IntPair(admsNodeID_A,admsNodeID_K));
    jacobianElements.push_back(IntPair(admsNodeID_K,admsNodeID_A));
    jacobianElements.push_back(IntPair(admsNodeID_K,admsNodeID_K));



  setDefaultParams();
  setParams(instance_block.params);

  // Real bogosity here...
  if (!given("XYCEADMSINSTTEMP"))
    admsInstTemp=getDeviceOptions().temp.getImmutableValue<double>();

  //calculate any parameters specified as expressions
  updateDependentParameters();

  // calculate dependent (i.e. computed params) and check for errors.
  processParams();

  PairVector collapsedNodes;

// Now generate the jacstamp from what we already have.
// This jacstamp will have all the correct node mapping.  map will be the nodal mapping of original
// node IDs to row/column ids in the reduced (non-sparse) representation of the jacobian.
// (for devices that have no collapsibles, this will be static, so check that it hasn't already
// been filled in)
if (jacStamp.empty())
{
int originalSize = 2+0;
computeJacStampAndMaps(jacobianElements,collapsedNodes,jacStamp,nodeMap,pairToJacStampMap,originalSize);
}

}

//-----------------------------------------------------------------------------
// Function      : Instance::~Instance
// Purpose       : destructor
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
Instance::~Instance()
{
}

//-----------------------------------------------------------------------------
// Function      : Instance::registerLIDs
// Purpose       : function for registering, and setting up, local IDs.
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
void Instance::registerLIDs( const LocalIdVector & intLIDVecRef,
                             const LocalIdVector & extLIDVecRef)
{
  AssertLIDs(intLIDVecRef.size() == numIntVars);
  AssertLIDs(extLIDVecRef.size() == numExtVars);

  LocalIdVector localLIDVec;

  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
  {
    Xyce::dout() << std::endl << section_divider << std::endl
                 << "In ADMSJUNCAP200::Instance::register LIDs\n\n"
                 << "name             = " << getName() << std::endl
                 << "number of internal variables: " << numIntVars << std::endl
                 << "number of external variables: " << numExtVars << std::endl;
  }

  // copy over the global ID lists into a local array.
  // The end result of this is an array of LIDs corresponding to all the
  // nodes we actually have, in the order that topology thinks of them
  intLIDVec = intLIDVecRef;
  extLIDVec = extLIDVecRef;
  localLIDVec.resize(numExtVars+numIntVars);
  for (int localNodeIndex=0;localNodeIndex<numExtVars;++localNodeIndex)
  {
    localLIDVec[localNodeIndex]=extLIDVec[localNodeIndex];
  }
  for (int localNodeIndex=numExtVars;localNodeIndex<numExtVars+numIntVars;++localNodeIndex)
  {
    localLIDVec[localNodeIndex]=intLIDVec[localNodeIndex-numExtVars];
    }

  // Now pull the LIDs for each of our nodes out of the local array.
  // Use the node mapping created by createJacStampAndMaps to handle
  // all the node collapse complications.
  li_A = localLIDVec[nodeMap[admsNodeID_A]];
  li_K = localLIDVec[nodeMap[admsNodeID_K]];


  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS))
  {
    Xyce::dout() << "\nSolution and RHS variables:\n";
      Xyce::dout() << "\nli_A = " << li_A << std::endl;
      Xyce::dout() << "\nli_K = " << li_K << std::endl;

    Xyce::dout() << "\nEnd of ADMSJUNCAP200::Instance::register LIDs\n";
    Xyce::dout() << section_divider << std::endl;
  }
}

//-----------------------------------------------------------------------------
// Function      : Instance::loadNodeSymbols
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
void Instance::loadNodeSymbols(Util::SymbolTable &symbol_table) const
{
    addStoreNode(symbol_table, li_store_vak, getName().getEncodedName() + ":vak");
    addStoreNode(symbol_table, li_store_cj, getName().getEncodedName() + ":cj");
    addStoreNode(symbol_table, li_store_cjbot, getName().getEncodedName() + ":cjbot");
    addStoreNode(symbol_table, li_store_cjgat, getName().getEncodedName() + ":cjgat");
    addStoreNode(symbol_table, li_store_cjsti, getName().getEncodedName() + ":cjsti");
    addStoreNode(symbol_table, li_store_ij, getName().getEncodedName() + ":ij");
    addStoreNode(symbol_table, li_store_ijbot, getName().getEncodedName() + ":ijbot");
    addStoreNode(symbol_table, li_store_ijgat, getName().getEncodedName() + ":ijgat");
    addStoreNode(symbol_table, li_store_ijsti, getName().getEncodedName() + ":ijsti");
    addStoreNode(symbol_table, li_store_si, getName().getEncodedName() + ":si");
    addStoreNode(symbol_table, li_store_idsatsbot, getName().getEncodedName() + ":idsatsbot");
    addStoreNode(symbol_table, li_store_idsatssti, getName().getEncodedName() + ":idsatssti");
    addStoreNode(symbol_table, li_store_idsatsgat, getName().getEncodedName() + ":idsatsgat");
    addStoreNode(symbol_table, li_store_cjosbot, getName().getEncodedName() + ":cjosbot");
    addStoreNode(symbol_table, li_store_cjossti, getName().getEncodedName() + ":cjossti");
    addStoreNode(symbol_table, li_store_cjosgat, getName().getEncodedName() + ":cjosgat");
    addStoreNode(symbol_table, li_store_vbisbot, getName().getEncodedName() + ":vbisbot");
    addStoreNode(symbol_table, li_store_vbissti, getName().getEncodedName() + ":vbissti");
    addStoreNode(symbol_table, li_store_vbisgat, getName().getEncodedName() + ":vbisgat");

  if (loadLeadCurrent)
  {
    addBranchDataNode( symbol_table, li_branch_iA, getName(), "BRANCH_D");


  }
}

//-----------------------------------------------------------------------------
// Function      : Instance::registerStoreLIDs
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
void Instance::registerStoreLIDs( const LocalIdVector & stoLIDVecRef)
{
  AssertLIDs(stoLIDVecRef.size() == getNumStoreVars());

  int numSto = stoLIDVecRef.size();
  if (numSto > 0)
  {
    int i=0;
    stoLIDVec = stoLIDVecRef;

      li_store_vak= stoLIDVec[i++];
      li_store_cj= stoLIDVec[i++];
      li_store_cjbot= stoLIDVec[i++];
      li_store_cjgat= stoLIDVec[i++];
      li_store_cjsti= stoLIDVec[i++];
      li_store_ij= stoLIDVec[i++];
      li_store_ijbot= stoLIDVec[i++];
      li_store_ijgat= stoLIDVec[i++];
      li_store_ijsti= stoLIDVec[i++];
      li_store_si= stoLIDVec[i++];
      li_store_idsatsbot= stoLIDVec[i++];
      li_store_idsatssti= stoLIDVec[i++];
      li_store_idsatsgat= stoLIDVec[i++];
      li_store_cjosbot= stoLIDVec[i++];
      li_store_cjossti= stoLIDVec[i++];
      li_store_cjosgat= stoLIDVec[i++];
      li_store_vbisbot= stoLIDVec[i++];
      li_store_vbissti= stoLIDVec[i++];
      li_store_vbisgat= stoLIDVec[i++];
  }
}

//-----------------------------------------------------------------------------
// Function      : Instance::registerBranchDataLIDs
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       : Eric Keiter, SNL
// Creation Date : 12/09/11
//-----------------------------------------------------------------------------
void Instance::registerBranchDataLIDs(const std::vector<int> & branchLIDVecRef)
{
  AssertLIDs(branchLIDVecRef.size() == getNumBranchDataVars());

  if (loadLeadCurrent)
  {
    li_branch_iA = branchLIDVecRef[0];

  }
}

//-----------------------------------------------------------------------------
// Function      : Instance::jacobianStamp
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
const JacobianStamp & Instance::jacobianStamp() const
{
    return jacStamp;
}

//-----------------------------------------------------------------------------
// Function      : Instance::registerJacLIDs
// Purpose       : Create Offset variables used for referencing jacobian
//                 elements
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
void Instance::registerJacLIDs( const JacobianStamp & jacLIDVec)
{
  DeviceInstance::registerJacLIDs(jacLIDVec);  IntPair jacLoc;
    jacLoc = pairToJacStampMap[IntPair(admsNodeID_A,admsNodeID_A)];
    A_A_Equ_A_NodeOffset = jacLIDVec[jacLoc.first][jacLoc.second];
    jacLoc = pairToJacStampMap[IntPair(admsNodeID_A,admsNodeID_K)];
    A_A_Equ_K_NodeOffset = jacLIDVec[jacLoc.first][jacLoc.second];
    jacLoc = pairToJacStampMap[IntPair(admsNodeID_K,admsNodeID_A)];
    A_K_Equ_A_NodeOffset = jacLIDVec[jacLoc.first][jacLoc.second];
    jacLoc = pairToJacStampMap[IntPair(admsNodeID_K,admsNodeID_K)];
    A_K_Equ_K_NodeOffset = jacLIDVec[jacLoc.first][jacLoc.second];


}

//-----------------------------------------------------------------------------
// Function      : Instance::setupPointers
// Purpose       : Create pointer variables used for referencing jacobian
//                 elements
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
void Instance::setupPointers( )
{

  Linear::Matrix & dFdx = *(extData.dFdxMatrixPtr);
  Linear::Matrix & dQdx = *(extData.dQdxMatrixPtr);
    f_A_Equ_A_Node_Ptr = &(dFdx[li_A][A_A_Equ_A_NodeOffset]);
    q_A_Equ_A_Node_Ptr = &(dQdx[li_A][A_A_Equ_A_NodeOffset]);
    f_A_Equ_K_Node_Ptr = &(dFdx[li_A][A_A_Equ_K_NodeOffset]);
    q_A_Equ_K_Node_Ptr = &(dQdx[li_A][A_A_Equ_K_NodeOffset]);
    f_K_Equ_A_Node_Ptr = &(dFdx[li_K][A_K_Equ_A_NodeOffset]);
    q_K_Equ_A_Node_Ptr = &(dQdx[li_K][A_K_Equ_A_NodeOffset]);
    f_K_Equ_K_Node_Ptr = &(dFdx[li_K][A_K_Equ_K_NodeOffset]);
    q_K_Equ_K_Node_Ptr = &(dQdx[li_K][A_K_Equ_K_NodeOffset]);


}

// RHS load functions

//-----------------------------------------------------------------------------
// Function      : Instance::loadDAEFVector
// Purpose       : load F vector (static contributions) for one instance for
//                 NEW DAE formulation
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
bool Instance::loadDAEFVector()
{

  bool bsuccess=true;
(*extData.daeFVectorPtr)[li_A] += staticContributions[admsNodeID_A];
(*extData.daeFVectorPtr)[li_K] += staticContributions[admsNodeID_K];


  if (loadLeadCurrent)
  {
    double * leadF = extData.nextLeadCurrFCompRawPtr;
    leadF[li_branch_iA] = leadCurrentF[0];



    // here we have to do special things for BJTs, MOSFETs and 2-terminal
    // devices for power computation.

        double * solVec = extData.nextSolVectorRawPtr;
        double * junctionV = extData.nextJunctionVCompRawPtr;
        junctionV[li_branch_iA] = solVec[li_A] - solVec[li_K];

  }
  return bsuccess;
}

//-----------------------------------------------------------------------------
// Function      : Instance::loadDAEQVector
// Purpose       : load Q vector (dynamic contributions) for one instance for
//                 NEW DAE formulation
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
bool Instance::loadDAEQVector()
{
(*extData.daeQVectorPtr)[li_A] += dynamicContributions[admsNodeID_A];
(*extData.daeQVectorPtr)[li_K] += dynamicContributions[admsNodeID_K];


  if (loadLeadCurrent)
  {
    double * leadQ = extData.nextLeadCurrQCompRawPtr;
    leadQ[li_branch_iA] = leadCurrentQ[0];


  }
  return true;
}


//-----------------------------------------------------------------------------
// Function      : Instance::updatePrimaryState
// Purpose       :
// Special Notes : In this initial implementation, does little more than
//                 call updateIntermediateVars()
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
bool Instance::updatePrimaryState()
{
  bool bsuccess = true;

  bsuccess = updateIntermediateVars();

  // if old DAE were implemented, we'd save dynamic contributions as state
  // here.

  double * stoVec = extData.nextStoVectorRawPtr;
  // Also need to save limited voltage drops and output vars
  // This formulation assumes that we have *always* written the
  // limited voltages back into the probeVars[] array.

  stoVec[li_store_vak] = vak;
  stoVec[li_store_cj] = cj;
  stoVec[li_store_cjbot] = cjbot;
  stoVec[li_store_cjgat] = cjgat;
  stoVec[li_store_cjsti] = cjsti;
  stoVec[li_store_ij] = ij;
  stoVec[li_store_ijbot] = ijbot;
  stoVec[li_store_ijgat] = ijgat;
  stoVec[li_store_ijsti] = ijsti;
  stoVec[li_store_si] = si;
  stoVec[li_store_idsatsbot] = idsatsbot;
  stoVec[li_store_idsatssti] = idsatssti;
  stoVec[li_store_idsatsgat] = idsatsgat;
  stoVec[li_store_cjosbot] = cjosbot;
  stoVec[li_store_cjossti] = cjossti;
  stoVec[li_store_cjosgat] = cjosgat;
  stoVec[li_store_vbisbot] = vbisbot;
  stoVec[li_store_vbissti] = vbissti;
  stoVec[li_store_vbisgat] = vbisgat;

  return bsuccess;
}

//-----------------------------------------------------------------------------
// Function      : Instance::updateSecondaryState
// Purpose       :
// Special Notes : In this initial implementation, does nothing
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
bool Instance::updateSecondaryState()
{
  bool bsuccess = true;

  // were old DAE implemented, we'd pull dynamic contribution derivatives
  // out of state.

  return bsuccess;
}

//-----------------------------------------------------------------------------
// Function      : Instance::updateIntermediateVars
// Purpose       : update intermediate variables for one JUNCAP200 instance
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
bool Instance::updateIntermediateVars()
{

  bool bsuccess=true;
  Linear::Vector * solVectorPtr = extData.nextSolVectorPtr;

  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) && getSolverState().debugTimeFlag)
  {
    Xyce::dout() << std::endl << subsection_divider << std::endl;
    Xyce::dout() << "  In ADMSJUNCAP200::Instance::updateIntermediateVars\n\n";
    Xyce::dout() << "  name = " << getName() << std::endl;
  }

  // Local variables
  double h1=0.0;
  double h2=0.0;
  double h2d=0.0;
     double d_h2d_dV_A_K=0.0;
  double h3=0.0;
     double d_h3_dV_A_K=0.0;
  double h4=0.0;
     double d_h4_dV_A_K=0.0;
  double h5=0.0;
     double d_h5_dV_A_K=0.0;
  double ijunrev=0.0;
     double d_ijunrev_dV_A_K=0.0;
  double ijunfor2=0.0;
     double d_ijunfor2_dV_A_K=0.0;
  double ijunfor1=0.0;
     double d_ijunfor1_dV_A_K=0.0;
  double tm1=0.0;
     double d_tm1_dV_A_K=0.0;
  double tm0=0.0;
     double d_tm0_dV_A_K=0.0;
  double fbreakdown=0.0;
     double d_fbreakdown_dV_A_K=0.0;
  double ibbt=0.0;
     double d_ibbt_dV_A_K=0.0;
  double Fmaxr=0.0;
     double d_Fmaxr_dV_A_K=0.0;
  double itat=0.0;
     double d_itat_dV_A_K=0.0;
  double gammamax=0.0;
     double d_gammamax_dV_A_K=0.0;
  double erfctimesexpmtat=0.0;
     double d_erfctimesexpmtat_dV_A_K=0.0;
  double erfcpos=0.0;
     double d_erfcpos_dV_A_K=0.0;
  double terfc=0.0;
     double d_terfc_dV_A_K=0.0;
  double ysq=0.0;
     double d_ysq_dV_A_K=0.0;
  double xerfc=0.0;
     double d_xerfc_dV_A_K=0.0;
  double mtat=0.0;
     double d_mtat_dV_A_K=0.0;
  double ltat=0.0;
     double d_ltat_dV_A_K=0.0;
  double ktat=0.0;
     double d_ktat_dV_A_K=0.0;
  double wtat=0.0;
     double d_wtat_dV_A_K=0.0;
  double wgamma=0.0;
     double d_wgamma_dV_A_K=0.0;
  double umaxpoweronepointfive=0.0;
     double d_umaxpoweronepointfive_dV_A_K=0.0;
  double sqrtumax=0.0;
     double d_sqrtumax_dV_A_K=0.0;
  double umax=0.0;
     double d_umax_dV_A_K=0.0;
  double umaxbeforelimiting=0.0;
     double d_umaxbeforelimiting_dV_A_K=0.0;
  double twoatatoverthreebtat=0.0;
     double d_twoatatoverthreebtat_dV_A_K=0.0;
  double btat=0.0;
     double d_btat_dV_A_K=0.0;
  double isrh=0.0;
     double d_isrh_dV_A_K=0.0;
  double asrh=0.0;
     double d_asrh_dV_A_K=0.0;
  double wdep=0.0;
     double d_wdep_dV_A_K=0.0;
  double wsrh=0.0;
     double d_wsrh_dV_A_K=0.0;
  double dwsrh=0.0;
     double d_dwsrh_dV_A_K=0.0;
  double wsrhstep=0.0;
     double d_wsrhstep_dV_A_K=0.0;
  double vbi_minus_vjsrh=0.0;
     double d_vbi_minus_vjsrh_dV_A_K=0.0;
  double id=0.0;
     double d_id_dV_A_K=0.0;
  double tmp=0.0;
     double d_tmp_dV_A_K=0.0;
  double vav=0.0;
     double d_vav_dV_A_K=0.0;
  double vjsrh=0.0;
     double d_vjsrh_dV_A_K=0.0;
  double vjlim=0.0;
     double d_vjlim_dV_A_K=0.0;
  double z=0.0;
     double d_z_dV_A_K=0.0;
  double idmult=0.0;
     double d_idmult_dV_A_K=0.0;
  double zinv=0.0;
     double d_zinv_dV_A_K=0.0;
  double vj=0.0;
     double d_vj_dV_A_K=0.0;
  double two_psistar=0.0;
     double d_two_psistar_dV_A_K=0.0;
  double vbbt=0.0;
     double d_vbbt_dV_A_K=0.0;


  // set the sizes of the Fad arrays:

  if (probeVars.size() != (2))
  {
    probeVars.resize(2);
    d_probeVars.resize(2);
    for (int i=0;i<2;i++)
    {
      d_probeVars[i].resize(2);
      for (int j=0;j<2;j++)
        d_probeVars[i][j]=0.0;
    }
    staticContributions.resize(2+0);
    d_staticContributions.resize(2+0);
    for (int i=0;i<2+0;i++)
      d_staticContributions[i].resize(2);
    dynamicContributions.resize(2+0);
    d_dynamicContributions.resize(2+0);
    for (int i=0;i<2+0;i++)
      d_dynamicContributions[i].resize(2);
  }

    noiseContribsPower.resize(1);
    noiseContribsExponent.resize(1);

  // initialize contributions to zero (automatically sets derivatives to zero)
  for (int i=0; i < 2+0 ; ++i)
  {
     staticContributions[i]=0;
     for (int j=0;j<2;j++)
        d_staticContributions[i][j] = 0.0;
     dynamicContributions[i]=0;
     for (int j=0;j<2;j++)
        d_dynamicContributions[i][j] = 0.0;
  }

  // extract solution variables and set as Fad independent variables.
probeVars[admsProbeID_V_A_GND] = (*solVectorPtr)[li_A];
d_probeVars[admsProbeID_V_A_GND][admsProbeID_V_A_GND] = 1.0;
probeVars[admsProbeID_V_A_K] = (*solVectorPtr)[li_A] - (*solVectorPtr)[li_K];
d_probeVars[admsProbeID_V_A_K][admsProbeID_V_A_K] = 1.0;
// -- code converted from analog/code block
//Begin block evaluateblock
{
//Block-local variables for block evaluateblock
double ijunbot=0.0;
     double d_ijunbot_dV_A_K=0.0;
double qjunbot=0.0;
     double d_qjunbot_dV_A_K=0.0;
double ijunsti=0.0;
     double d_ijunsti_dV_A_K=0.0;
double qjunsti=0.0;
     double d_qjunsti_dV_A_K=0.0;
double ijungat=0.0;
     double d_ijungat_dV_A_K=0.0;
double qjungat=0.0;
     double d_qjungat_dV_A_K=0.0;
double ijun=0.0;
     double d_ijun_dV_A_K=0.0;
double qjun=0.0;
     double d_qjun_dV_A_K=0.0;
double jnoise=0.0;
double VAK=0.0;
     double d_VAK_dV_A_K=0.0;
//End of Block-local variables

d_ijun_dV_A_K =  0.0;
ijun = 0.0;

d_ijunbot_dV_A_K =  0.0;
ijunbot = 0.0;

d_ijunsti_dV_A_K =  0.0;
ijunsti = 0.0;

d_ijungat_dV_A_K =  0.0;
ijungat = 0.0;
//Begin block evaluateStaticDynamic
{

d_VAK_dV_A_K = (model_.TYPE)*d_probeVars[admsProbeID_V_A_K][admsProbeID_V_A_K];
VAK = ((model_.TYPE)*(probeVars[admsProbeID_V_A_K]));
if (((model_.SWJUNEXP_i)==1.0))
{

d_tm0_dV_A_K = d_VAK_dV_A_K*(model_.phitdinv)*MFOR1;
tm0 = ((VAK*(model_.phitdinv))*MFOR1);
{
double value_exp_0 = exp(tm0);
double  deriv_exp_0_d0 = value_exp_0;

d_tm1_dV_A_K = ((tm0<(-2.3025850929940458e+02))?(-1.0e-100*(-d_tm0_dV_A_K)/(((-2.3025850929940458e+02)-tm0)+1.0)/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>xhighf1)?expxhf1*d_tm0_dV_A_K:(deriv_exp_0_d0*(d_tm0_dV_A_K))));
tm1 = ((tm0<(-2.3025850929940458e+02))?(1.0e-100/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>xhighf1)?(expxhf1*((tm0-xhighf1)+1.0)):value_exp_0));
}

d_ijunfor1_dV_A_K = ISATFOR1*d_tm1_dV_A_K;
ijunfor1 = (ISATFOR1*(tm1-1.0));

d_tm0_dV_A_K = d_VAK_dV_A_K*(model_.phitdinv)*MFOR2;
tm0 = ((VAK*(model_.phitdinv))*MFOR2);
{
double value_exp_0 = exp(tm0);
double  deriv_exp_0_d0 = value_exp_0;

d_tm1_dV_A_K = ((tm0<(-2.3025850929940458e+02))?(-1.0e-100*(-d_tm0_dV_A_K)/(((-2.3025850929940458e+02)-tm0)+1.0)/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>xhighf2)?expxhf2*d_tm0_dV_A_K:(deriv_exp_0_d0*(d_tm0_dV_A_K))));
tm1 = ((tm0<(-2.3025850929940458e+02))?(1.0e-100/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>xhighf2)?(expxhf2*((tm0-xhighf2)+1.0)):value_exp_0));
}

d_ijunfor2_dV_A_K = ISATFOR2*d_tm1_dV_A_K;
ijunfor2 = (ISATFOR2*(tm1-1.0));

d_ijunrev_dV_A_K =  0.0;
ijunrev = 0.0;
if ((m0flag>0.0))
{

d_ijunrev_dV_A_K = (VAK*d_VAK_dV_A_K*MREV+d_VAK_dV_A_K*(ISATREV+(VAK*MREV)));
ijunrev = (VAK*(ISATREV+(VAK*MREV)));
}
else
{

d_tm0_dV_A_K = (-d_VAK_dV_A_K)*(model_.phitdinv)*MREV;
tm0 = (((-VAK)*(model_.phitdinv))*MREV);
{
double value_exp_0 = exp(tm0);
double  deriv_exp_0_d0 = value_exp_0;

d_tm1_dV_A_K = ((tm0<(-2.3025850929940458e+02))?(-1.0e-100*(-d_tm0_dV_A_K)/(((-2.3025850929940458e+02)-tm0)+1.0)/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>xhighr)?expxhr*d_tm0_dV_A_K:(deriv_exp_0_d0*(d_tm0_dV_A_K))));
tm1 = ((tm0<(-2.3025850929940458e+02))?(1.0e-100/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>xhighr)?(expxhr*((tm0-xhighr)+1.0)):value_exp_0));
}

d_ijunrev_dV_A_K = (-ISATREV)*d_tm1_dV_A_K;
ijunrev = ((-ISATREV)*(tm1-1.0));
}

d_ijun_dV_A_K = ((d_ijunfor1_dV_A_K+d_ijunfor2_dV_A_K)+d_ijunrev_dV_A_K);
ijun = ((ijunfor1+ijunfor2)+ijunrev);
//Begin block evaluateDynamic
{
//Block-local variables for block evaluateDynamic
double tmpv=0.0;
     double d_tmpv_dV_A_K=0.0;
double vjv=0.0;
     double d_vjv_dV_A_K=0.0;
//End of Block-local variables

d_tmpv_dV_A_K =  0.0;
tmpv = 0.0;

d_vjv_dV_A_K =  0.0;
vjv = 0.0;
h1 = ((4.0*vch)*vch);
h2 = (vch/vfmin);

d_h2d_dV_A_K = d_VAK_dV_A_K;
h2d = (VAK+(vch*h2));

d_h3_dV_A_K = d_h2d_dV_A_K;
h3 = (vfmin+h2d);

d_h4_dV_A_K = (-d_h2d_dV_A_K);
h4 = (vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_h5_dV_A_K = (deriv_sqrt_0_d0*((h4*d_h4_dV_A_K+d_h4_dV_A_K*h4)));
h5 = value_sqrt_0;
}

d_vjv_dV_A_K = 2.0*(((h3+h5)*d_VAK_dV_A_K*vfmin-(VAK*vfmin)*(d_h3_dV_A_K+d_h5_dV_A_K))/(h3+h5)/(h3+h5));
vjv = (2.0*((VAK*vfmin)/(h3+h5)));
if ((zflagbot>0.5))
{
if (((model_.one_minus_PBOT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vjv*(model_.vbiinvbot))));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmpv_dV_A_K = (deriv_sqrt_0_d0*((-d_vjv_dV_A_K*(model_.vbiinvbot))));
tmpv = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vjv*(model_.vbiinvbot))),(model_.one_minus_PBOT));
double  deriv_pow_0_d0 = (((1.0-(vjv*(model_.vbiinvbot))) == 0.0)?0.0:(value_pow_0*(model_.one_minus_PBOT)/(1.0-(vjv*(model_.vbiinvbot)))));

d_tmpv_dV_A_K = (deriv_pow_0_d0*((-d_vjv_dV_A_K*(model_.vbiinvbot))));
tmpv = value_pow_0;
}
}

d_qjunbot_dV_A_K = ((model_.qprefbot)*(-d_tmpv_dV_A_K)+(model_.qpref2bot)*(d_VAK_dV_A_K-d_vjv_dV_A_K));
qjunbot = (((model_.qprefbot)*(1.0-tmpv))+((model_.qpref2bot)*(VAK-vjv)));
}
if ((zflagsti>0.5))
{
if (((model_.one_minus_PSTI)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vjv*(model_.vbiinvsti))));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmpv_dV_A_K = (deriv_sqrt_0_d0*((-d_vjv_dV_A_K*(model_.vbiinvsti))));
tmpv = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vjv*(model_.vbiinvsti))),(model_.one_minus_PSTI));
double  deriv_pow_0_d0 = (((1.0-(vjv*(model_.vbiinvsti))) == 0.0)?0.0:(value_pow_0*(model_.one_minus_PSTI)/(1.0-(vjv*(model_.vbiinvsti)))));

d_tmpv_dV_A_K = (deriv_pow_0_d0*((-d_vjv_dV_A_K*(model_.vbiinvsti))));
tmpv = value_pow_0;
}
}

d_qjunsti_dV_A_K = ((model_.qprefsti)*(-d_tmpv_dV_A_K)+(model_.qpref2sti)*(d_VAK_dV_A_K-d_vjv_dV_A_K));
qjunsti = (((model_.qprefsti)*(1.0-tmpv))+((model_.qpref2sti)*(VAK-vjv)));
}
if ((zflaggat>0.5))
{
if (((model_.one_minus_PGAT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vjv*(model_.vbiinvgat))));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmpv_dV_A_K = (deriv_sqrt_0_d0*((-d_vjv_dV_A_K*(model_.vbiinvgat))));
tmpv = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vjv*(model_.vbiinvgat))),(model_.one_minus_PGAT));
double  deriv_pow_0_d0 = (((1.0-(vjv*(model_.vbiinvgat))) == 0.0)?0.0:(value_pow_0*(model_.one_minus_PGAT)/(1.0-(vjv*(model_.vbiinvgat)))));

d_tmpv_dV_A_K = (deriv_pow_0_d0*((-d_vjv_dV_A_K*(model_.vbiinvgat))));
tmpv = value_pow_0;
}
}

d_qjungat_dV_A_K = ((model_.qprefgat)*(-d_tmpv_dV_A_K)+(model_.qpref2gat)*(d_VAK_dV_A_K-d_vjv_dV_A_K));
qjungat = (((model_.qprefgat)*(1.0-tmpv))+((model_.qpref2gat)*(VAK-vjv)));
}
}
// End block evaluateDynamic
}
else
{

d_vbbt_dV_A_K =  0.0;
vbbt = 0.0;

d_two_psistar_dV_A_K =  0.0;
two_psistar = 0.0;
if ((!(((AB_i==0.0)&&(LS_i==0.0))&&(LG_i==0.0))))
{
h1 = ((4.0*vch)*vch);
h2 = (vch/vfmin);

d_h2d_dV_A_K = d_VAK_dV_A_K;
h2d = (VAK+(vch*h2));

d_h3_dV_A_K = d_h2d_dV_A_K;
h3 = (vfmin+h2d);

d_h4_dV_A_K = (-d_h2d_dV_A_K);
h4 = (vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_h5_dV_A_K = (deriv_sqrt_0_d0*((h4*d_h4_dV_A_K+d_h4_dV_A_K*h4)));
h5 = value_sqrt_0;
}

d_vj_dV_A_K = 2.0*(((h3+h5)*d_VAK_dV_A_K*vfmin-(VAK*vfmin)*(d_h3_dV_A_K+d_h5_dV_A_K))/(h3+h5)/(h3+h5));
vj = (2.0*((VAK*vfmin)/(h3+h5)));
if ((VAK<VMAX))
{
if ((fabs((0.5*(VAK*(model_.phitdinv))))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(VAK*(model_.phitdinv))));
double  deriv_exp_0_d0 = value_exp_0;

d_zinv_dV_A_K = (deriv_exp_0_d0*(0.5*d_VAK_dV_A_K*(model_.phitdinv)));
zinv = value_exp_0;
}
}
else
{
if (((0.5*(VAK*(model_.phitdinv)))<0.0))
{

d_zinv_dV_A_K = (-1.0e-100*(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*0.5*(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*(-0.5*d_VAK_dV_A_K*(model_.phitdinv))*3.3333333333333333e-01+(-0.5*d_VAK_dV_A_K*(model_.phitdinv))*(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*3.3333333333333333e-01)))+(-0.5*d_VAK_dV_A_K*(model_.phitdinv))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*3.3333333333333333e-01))))))));
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*(model_.phitdinv))))*3.3333333333333333e-01))))))));
}
else
{

d_zinv_dV_A_K = 1.0e100*(((0.5*(VAK*(model_.phitdinv)))-2.3025850929940458e+02)*0.5*(((0.5*(VAK*(model_.phitdinv)))-2.3025850929940458e+02)*0.5*d_VAK_dV_A_K*(model_.phitdinv)*3.3333333333333333e-01+0.5*d_VAK_dV_A_K*(model_.phitdinv)*(1.0+(((0.5*(VAK*(model_.phitdinv)))-2.3025850929940458e+02)*3.3333333333333333e-01)))+0.5*d_VAK_dV_A_K*(model_.phitdinv)*(1.0+(0.5*(((0.5*(VAK*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(((0.5*(VAK*(model_.phitdinv)))-2.3025850929940458e+02)*3.3333333333333333e-01))))));
zinv = (1.0e100*(1.0+(((0.5*(VAK*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(VAK*(model_.phitdinv)))-2.3025850929940458e+02)*(1.0+(((0.5*(VAK*(model_.phitdinv)))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}

d_idmult_dV_A_K = (zinv*d_zinv_dV_A_K+d_zinv_dV_A_K*zinv);
idmult = (zinv*zinv);
}
else
{

d_idmult_dV_A_K = d_VAK_dV_A_K*(model_.phitdinv)*exp_VMAX_over_phitd;
idmult = ((1.0+((VAK-VMAX)*(model_.phitdinv)))*exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_zinv_dV_A_K = (deriv_sqrt_0_d0*(d_idmult_dV_A_K));
zinv = value_sqrt_0;
}
}

idmult = (idmult-1.0);

d_z_dV_A_K = (-d_zinv_dV_A_K/zinv/zinv);
z = (1.0/zinv);
if ((VAK>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/((2.0+z)+value_sqrt_0));

d_two_psistar_dV_A_K = 2.0*(model_.phitd)*(deriv_log_1_d0*((d_z_dV_A_K+(deriv_sqrt_0_d0*(((z+1.0)*d_z_dV_A_K+d_z_dV_A_K*(z+3.0)))))));
two_psistar = (2.0*((model_.phitd)*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/(((2.0*zinv)+1.0)+value_sqrt_0));

d_two_psistar_dV_A_K = ((-d_VAK_dV_A_K)+2.0*(model_.phitd)*(deriv_log_1_d0*((2.0*d_zinv_dV_A_K+(deriv_sqrt_0_d0*(((1.0+zinv)*3.0*d_zinv_dV_A_K+d_zinv_dV_A_K*(1.0+(3.0*zinv)))))))));
two_psistar = ((-VAK)+(2.0*((model_.phitd)*value_log_1)));
}
}

d_vjlim_dV_A_K = (-d_two_psistar_dV_A_K);
vjlim = (vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((VAK-vjlim)*(VAK-vjlim))+((4.0*(model_.phitd))*(model_.phitd))));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_vjsrh_dV_A_K = 0.5*((d_VAK_dV_A_K+d_vjlim_dV_A_K)-(deriv_sqrt_0_d0*(((VAK-vjlim)*(d_VAK_dV_A_K-d_vjlim_dV_A_K)+(d_VAK_dV_A_K-d_vjlim_dV_A_K)*(VAK-vjlim)))));
vjsrh = (0.5*((VAK+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((VAK-vbbtlim)*(VAK-vbbtlim))+((4.0*(model_.phitr))*(model_.phitr))));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_vbbt_dV_A_K = 0.5*(d_VAK_dV_A_K-(deriv_sqrt_0_d0*(((VAK-vbbtlim)*d_VAK_dV_A_K+d_VAK_dV_A_K*(VAK-vbbtlim)))));
vbbt = (0.5*((VAK+vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((VAK)*(VAK))+((4.0*1.0e-6)*1.0e-6)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_vav_dV_A_K = 0.5*(d_VAK_dV_A_K-(deriv_sqrt_0_d0*(((VAK)*d_VAK_dV_A_K+d_VAK_dV_A_K*(VAK)))));
vav = (0.5*(VAK-value_sqrt_0));
}
}
if ((AB_i==0.0))
{

d_ijunbot_dV_A_K =  0.0;
ijunbot = 0.0;

d_qjunbot_dV_A_K =  0.0;
qjunbot = 0.0;
}
else
{
if (((model_.one_minus_PBOT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvbot))));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmp_dV_A_K = (deriv_sqrt_0_d0*((-d_vj_dV_A_K*(model_.vbiinvbot))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvbot))),(model_.one_minus_PBOT));
double  deriv_pow_0_d0 = (((1.0-(vj*(model_.vbiinvbot))) == 0.0)?0.0:(value_pow_0*(model_.one_minus_PBOT)/(1.0-(vj*(model_.vbiinvbot)))));

d_tmp_dV_A_K = (deriv_pow_0_d0*((-d_vj_dV_A_K*(model_.vbiinvbot))));
tmp = value_pow_0;
}
}

d_qjunbot_dV_A_K = ((model_.qprefbot)*(-d_tmp_dV_A_K)+(model_.qpref2bot)*(d_VAK_dV_A_K-d_vj_dV_A_K));
qjunbot = (((model_.qprefbot)*(1.0-tmp))+((model_.qpref2bot)*(VAK-vj)));

d_id_dV_A_K = (model_.idsatbot)*d_idmult_dV_A_K;
id = ((model_.idsatbot)*idmult);
if ((((model_.CSRHBOT_i)==0.0)&&((model_.CTATBOT_i)==0.0)))
{

d_isrh_dV_A_K =  0.0;
isrh = 0.0;
}
else
{

d_vbi_minus_vjsrh_dV_A_K = (-d_vjsrh_dV_A_K);
vbi_minus_vjsrh = ((model_.vbibot)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_wsrhstep_dV_A_K = (-(deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dV_A_K-two_psistar*d_vbi_minus_vjsrh_dV_A_K)/vbi_minus_vjsrh/vbi_minus_vjsrh)))));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PBOT_i)==0.5))
{

d_dwsrh_dV_A_K =  0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);

d_dwsrh_dV_A_K = ((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*(deriv_log_0_d0*(d_wsrhstep_dV_A_K))+(wsrhstep*d_wsrhstep_dV_A_K+d_wsrhstep_dV_A_K*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dV_A_K))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dV_A_K)*(1.0-(2.0*(model_.PBOT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PBOT_i))));
}
}

d_wsrh_dV_A_K = (d_wsrhstep_dV_A_K+d_dwsrh_dV_A_K);
wsrh = (wsrhstep+dwsrh);
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRBOTinv)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmp_dV_A_K = (deriv_sqrt_0_d0*(d_vbi_minus_vjsrh_dV_A_K*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRBOTinv)),(model_.PBOT_i));
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*(model_.VBIRBOTinv)) == 0.0)?0.0:(value_pow_0*(model_.PBOT_i)/(vbi_minus_vjsrh*(model_.VBIRBOTinv))));

d_tmp_dV_A_K = (deriv_pow_0_d0*(d_vbi_minus_vjsrh_dV_A_K*(model_.VBIRBOTinv)));
tmp = value_pow_0;
}
}

d_wdep_dV_A_K = (model_.wdepnulrbot)*d_tmp_dV_A_K;
wdep = ((model_.wdepnulrbot)*tmp);

d_asrh_dV_A_K = (model_.ftdbot)*((zinv-1.0)*d_wdep_dV_A_K+d_zinv_dV_A_K*wdep);
asrh = ((model_.ftdbot)*((zinv-1.0)*wdep));

d_isrh_dV_A_K = (model_.CSRHBOT_i)*(asrh*d_wsrh_dV_A_K+d_asrh_dV_A_K*wsrh);
isrh = ((model_.CSRHBOT_i)*(asrh*wsrh));
}
if (((model_.CTATBOT_i)==0.0))
{

d_itat_dV_A_K =  0.0;
itat = 0.0;
}
else
{

d_btat_dV_A_K = (model_.btatpartbot)*((vbi_minus_vjsrh*d_wdep_dV_A_K*(model_.one_minus_PBOT)-(wdep*(model_.one_minus_PBOT))*d_vbi_minus_vjsrh_dV_A_K)/vbi_minus_vjsrh/vbi_minus_vjsrh);
btat = ((model_.btatpartbot)*((wdep*(model_.one_minus_PBOT))/vbi_minus_vjsrh));

d_twoatatoverthreebtat_dV_A_K = (-(0.666666666666667*(model_.atatbot))*d_btat_dV_A_K/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*(model_.atatbot))/btat);

d_umaxbeforelimiting_dV_A_K = (twoatatoverthreebtat*d_twoatatoverthreebtat_dV_A_K+d_twoatatoverthreebtat_dV_A_K*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_umax_dV_A_K = (deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dV_A_K+d_umaxbeforelimiting_dV_A_K*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dV_A_K+d_umaxbeforelimiting_dV_A_K*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0))));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);

d_sqrtumax_dV_A_K = (deriv_sqrt_1_d0*((deriv_fabs_0_d0*(d_umax_dV_A_K))));
sqrtumax = value_sqrt_1;
}

d_umaxpoweronepointfive_dV_A_K = (umax*d_sqrtumax_dV_A_K+d_umax_dV_A_K*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT))==(-1.0)))
{

d_wgamma_dV_A_K = (-(btat*d_umaxpoweronepointfive_dV_A_K+d_btat_dV_A_K*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT)));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-(model_.PBOT_i))*(model_.one_over_one_minus_PBOT))/(1.0+(btat*umaxpoweronepointfive))));

d_wgamma_dV_A_K = (deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dV_A_K+d_btat_dV_A_K*umaxpoweronepointfive)));
wgamma = value_pow_0;
}
}

d_wtat_dV_A_K = (((wsrh+wgamma)*(wsrh*d_wgamma_dV_A_K+d_wsrh_dV_A_K*wgamma)-(wsrh*wgamma)*(d_wsrh_dV_A_K+d_wgamma_dV_A_K))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_ktat_dV_A_K = (deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dV_A_K-btat*d_sqrtumax_dV_A_K)/sqrtumax/sqrtumax)));
ktat = value_sqrt_0;
}

d_ltat_dV_A_K = (2.0*(twoatatoverthreebtat*d_sqrtumax_dV_A_K+d_twoatatoverthreebtat_dV_A_K*sqrtumax)-d_umax_dV_A_K);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);

d_mtat_dV_A_K = (((((model_.atatbot)*twoatatoverthreebtat)*d_sqrtumax_dV_A_K+(model_.atatbot)*d_twoatatoverthreebtat_dV_A_K*sqrtumax)-(model_.atatbot)*d_umax_dV_A_K)+0.5*(btat*d_umaxpoweronepointfive_dV_A_K+d_btat_dV_A_K*umaxpoweronepointfive));
mtat = (((((model_.atatbot)*twoatatoverthreebtat)*sqrtumax)-((model_.atatbot)*umax))+(0.5*(btat*umaxpoweronepointfive)));

d_xerfc_dV_A_K = ((ltat-1.0)*d_ktat_dV_A_K+d_ltat_dV_A_K*ktat);
xerfc = ((ltat-1.0)*ktat);

d_ysq_dV_A_K = (xerfc*d_xerfc_dV_A_K+d_xerfc_dV_A_K*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{

d_terfc_dV_A_K = (-(model_.perfc)*d_xerfc_dV_A_K/(1.0+((model_.perfc)*xerfc))/(1.0+((model_.perfc)*xerfc)));
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{

d_terfc_dV_A_K = (-(-(model_.perfc)*d_xerfc_dV_A_K)/(1.0-((model_.perfc)*xerfc))/(1.0-((model_.perfc)*xerfc)));
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;

d_tmp_dV_A_K = (deriv_exp_0_d0*(((-d_ysq_dV_A_K)+d_mtat_dV_A_K)));
tmp = value_exp_0;
}
}
else
{

d_tmp_dV_A_K = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dV_A_K)+d_mtat_dV_A_K))*3.3333333333333333e-01+(-((-d_ysq_dV_A_K)+d_mtat_dV_A_K))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dV_A_K)+d_mtat_dV_A_K))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}

d_erfcpos_dV_A_K = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*d_tmp_dV_A_K+((0.29214664*d_terfc_dV_A_K+(model_.berfc)*(terfc*d_terfc_dV_A_K+d_terfc_dV_A_K*terfc))+(model_.cerfc)*((terfc*terfc)*d_terfc_dV_A_K+(terfc*d_terfc_dV_A_K+d_terfc_dV_A_K*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{

d_erfctimesexpmtat_dV_A_K = d_erfcpos_dV_A_K;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;

d_tmp_dV_A_K = (deriv_exp_0_d0*(d_mtat_dV_A_K));
tmp = value_exp_0;
}
}
else
{

d_tmp_dV_A_K = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dV_A_K)*3.3333333333333333e-01+(-d_mtat_dV_A_K)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dV_A_K)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}

d_erfctimesexpmtat_dV_A_K = (2.0*d_tmp_dV_A_K-d_erfcpos_dV_A_K);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}

d_gammamax_dV_A_K = (1.77245385090551603*0.5)*((ktat*(model_.atatbot)*d_erfctimesexpmtat_dV_A_K-((model_.atatbot)*erfctimesexpmtat)*d_ktat_dV_A_K)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*(((model_.atatbot)*erfctimesexpmtat)/ktat));

d_itat_dV_A_K = (model_.CTATBOT_i)*((asrh*gammamax)*d_wtat_dV_A_K+(asrh*d_gammamax_dV_A_K+d_asrh_dV_A_K*gammamax)*wtat);
itat = ((model_.CTATBOT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTBOT_i)==0.0))
{

d_ibbt_dV_A_K =  0.0;
ibbt = 0.0;
}
else
{
if (((model_.PBOT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmp_dV_A_K = (deriv_sqrt_0_d0*((-d_vbbt_dV_A_K)*(model_.VBIRBOTinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)),(model_.PBOT_i));
double  deriv_pow_0_d0 = (((((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv)) == 0.0)?0.0:(value_pow_0*(model_.PBOT_i)/(((model_.VBIRBOT_i)-vbbt)*(model_.VBIRBOTinv))));

d_tmp_dV_A_K = (deriv_pow_0_d0*((-d_vbbt_dV_A_K)*(model_.VBIRBOTinv)));
tmp = value_pow_0;
}
}

d_Fmaxr_dV_A_K = (model_.one_over_one_minus_PBOT)*((tmp*(-d_vbbt_dV_A_K)*(model_.wdepnulrinvbot)-(((model_.VBIRBOT_i)-vbbt)*(model_.wdepnulrinvbot))*d_tmp_dV_A_K)/tmp/tmp);
Fmaxr = ((model_.one_over_one_minus_PBOT)*((((model_.VBIRBOT_i)-vbbt)*(model_.wdepnulrinvbot))/tmp));
if ((fabs(((-(model_.fbbtbot))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtbot))/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;

d_tmp_dV_A_K = (deriv_exp_0_d0*((-(-(model_.fbbtbot))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtbot))/Fmaxr)<0.0))
{

d_tmp_dV_A_K = (-1.0e-100*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(-(-(-(model_.fbbtbot))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-(-(-(model_.fbbtbot))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*3.3333333333333333e-01)))+(-(-(-(model_.fbbtbot))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtbot))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{

d_tmp_dV_A_K = 1.0e100*((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*0.5*((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(-(-(model_.fbbtbot))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)*3.3333333333333333e-01+(-(-(model_.fbbtbot))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+(-(-(model_.fbbtbot))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)*(1.0+(0.5*((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtbot))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}

d_ibbt_dV_A_K = (model_.CBBTBOT_i)*(((VAK*Fmaxr)*Fmaxr)*d_tmp_dV_A_K+((VAK*Fmaxr)*d_Fmaxr_dV_A_K+(VAK*d_Fmaxr_dV_A_K+d_VAK_dV_A_K*Fmaxr)*Fmaxr)*tmp);
ibbt = ((model_.CBBTBOT_i)*(((VAK*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRBOT_i)>1.0e3))
{

d_fbreakdown_dV_A_K =  0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRBOT_i))))
{
if (((model_.PBRBOT_i)==4.0))
{

d_tmp_dV_A_K = ((((vav*(model_.VBRinvbot))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)))*d_vav_dV_A_K*(model_.VBRinvbot)+(((vav*(model_.VBRinvbot))*(vav*(model_.VBRinvbot)))*d_vav_dV_A_K*(model_.VBRinvbot)+((vav*(model_.VBRinvbot))*d_vav_dV_A_K*(model_.VBRinvbot)+d_vav_dV_A_K*(model_.VBRinvbot)*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)));
tmp = ((((vav*(model_.VBRinvbot))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)))*(vav*(model_.VBRinvbot)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvbot)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRBOT_i));
double  deriv_fabs_0_d0 = ((((vav*(model_.VBRinvbot)))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*(model_.PBRBOT_i)/value_fabs_0));

d_tmp_dV_A_K = (deriv_pow_1_d0*((deriv_fabs_0_d0*(d_vav_dV_A_K*(model_.VBRinvbot)))));
tmp = value_pow_1;
}
}

d_fbreakdown_dV_A_K = (-(-d_tmp_dV_A_K)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{

d_fbreakdown_dV_A_K = d_vav_dV_A_K*(model_.slopebot);
fbreakdown = ((model_.fstopbot)+((vav+((model_.alphaav)*(model_.VBRBOT_i)))*(model_.slopebot)));
}
}

d_ijunbot_dV_A_K = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dV_A_K+(((d_id_dV_A_K+d_isrh_dV_A_K)+d_itat_dV_A_K)+d_ibbt_dV_A_K)*fbreakdown);
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LS_i==0.0))
{

d_ijunsti_dV_A_K =  0.0;
ijunsti = 0.0;

d_qjunsti_dV_A_K =  0.0;
qjunsti = 0.0;
}
else
{
if (((model_.one_minus_PSTI)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvsti))));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmp_dV_A_K = (deriv_sqrt_0_d0*((-d_vj_dV_A_K*(model_.vbiinvsti))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvsti))),(model_.one_minus_PSTI));
double  deriv_pow_0_d0 = (((1.0-(vj*(model_.vbiinvsti))) == 0.0)?0.0:(value_pow_0*(model_.one_minus_PSTI)/(1.0-(vj*(model_.vbiinvsti)))));

d_tmp_dV_A_K = (deriv_pow_0_d0*((-d_vj_dV_A_K*(model_.vbiinvsti))));
tmp = value_pow_0;
}
}

d_qjunsti_dV_A_K = ((model_.qprefsti)*(-d_tmp_dV_A_K)+(model_.qpref2sti)*(d_VAK_dV_A_K-d_vj_dV_A_K));
qjunsti = (((model_.qprefsti)*(1.0-tmp))+((model_.qpref2sti)*(VAK-vj)));

d_id_dV_A_K = (model_.idsatsti)*d_idmult_dV_A_K;
id = ((model_.idsatsti)*idmult);
if ((((model_.CSRHSTI_i)==0.0)&&((model_.CTATSTI_i)==0.0)))
{

d_isrh_dV_A_K =  0.0;
isrh = 0.0;
}
else
{

d_vbi_minus_vjsrh_dV_A_K = (-d_vjsrh_dV_A_K);
vbi_minus_vjsrh = ((model_.vbisti)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_wsrhstep_dV_A_K = (-(deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dV_A_K-two_psistar*d_vbi_minus_vjsrh_dV_A_K)/vbi_minus_vjsrh/vbi_minus_vjsrh)))));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PSTI_i)==0.5))
{

d_dwsrh_dV_A_K =  0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);

d_dwsrh_dV_A_K = ((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*(deriv_log_0_d0*(d_wsrhstep_dV_A_K))+(wsrhstep*d_wsrhstep_dV_A_K+d_wsrhstep_dV_A_K*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dV_A_K))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dV_A_K)*(1.0-(2.0*(model_.PSTI_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PSTI_i))));
}
}

d_wsrh_dV_A_K = (d_wsrhstep_dV_A_K+d_dwsrh_dV_A_K);
wsrh = (wsrhstep+dwsrh);
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRSTIinv)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmp_dV_A_K = (deriv_sqrt_0_d0*(d_vbi_minus_vjsrh_dV_A_K*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRSTIinv)),(model_.PSTI_i));
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*(model_.VBIRSTIinv)) == 0.0)?0.0:(value_pow_0*(model_.PSTI_i)/(vbi_minus_vjsrh*(model_.VBIRSTIinv))));

d_tmp_dV_A_K = (deriv_pow_0_d0*(d_vbi_minus_vjsrh_dV_A_K*(model_.VBIRSTIinv)));
tmp = value_pow_0;
}
}

d_wdep_dV_A_K = (model_.wdepnulrsti)*d_tmp_dV_A_K;
wdep = ((model_.wdepnulrsti)*tmp);

d_asrh_dV_A_K = (model_.ftdsti)*((zinv-1.0)*d_wdep_dV_A_K+d_zinv_dV_A_K*wdep);
asrh = ((model_.ftdsti)*((zinv-1.0)*wdep));

d_isrh_dV_A_K = (model_.CSRHSTI_i)*(asrh*d_wsrh_dV_A_K+d_asrh_dV_A_K*wsrh);
isrh = ((model_.CSRHSTI_i)*(asrh*wsrh));
}
if (((model_.CTATSTI_i)==0.0))
{

d_itat_dV_A_K =  0.0;
itat = 0.0;
}
else
{

d_btat_dV_A_K = (model_.btatpartsti)*((vbi_minus_vjsrh*d_wdep_dV_A_K*(model_.one_minus_PSTI)-(wdep*(model_.one_minus_PSTI))*d_vbi_minus_vjsrh_dV_A_K)/vbi_minus_vjsrh/vbi_minus_vjsrh);
btat = ((model_.btatpartsti)*((wdep*(model_.one_minus_PSTI))/vbi_minus_vjsrh));

d_twoatatoverthreebtat_dV_A_K = (-(0.666666666666667*(model_.atatsti))*d_btat_dV_A_K/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*(model_.atatsti))/btat);

d_umaxbeforelimiting_dV_A_K = (twoatatoverthreebtat*d_twoatatoverthreebtat_dV_A_K+d_twoatatoverthreebtat_dV_A_K*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_umax_dV_A_K = (deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dV_A_K+d_umaxbeforelimiting_dV_A_K*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dV_A_K+d_umaxbeforelimiting_dV_A_K*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0))));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);

d_sqrtumax_dV_A_K = (deriv_sqrt_1_d0*((deriv_fabs_0_d0*(d_umax_dV_A_K))));
sqrtumax = value_sqrt_1;
}

d_umaxpoweronepointfive_dV_A_K = (umax*d_sqrtumax_dV_A_K+d_umax_dV_A_K*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI))==(-1.0)))
{

d_wgamma_dV_A_K = (-(btat*d_umaxpoweronepointfive_dV_A_K+d_btat_dV_A_K*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI)));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-(model_.PSTI_i))*(model_.one_over_one_minus_PSTI))/(1.0+(btat*umaxpoweronepointfive))));

d_wgamma_dV_A_K = (deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dV_A_K+d_btat_dV_A_K*umaxpoweronepointfive)));
wgamma = value_pow_0;
}
}

d_wtat_dV_A_K = (((wsrh+wgamma)*(wsrh*d_wgamma_dV_A_K+d_wsrh_dV_A_K*wgamma)-(wsrh*wgamma)*(d_wsrh_dV_A_K+d_wgamma_dV_A_K))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_ktat_dV_A_K = (deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dV_A_K-btat*d_sqrtumax_dV_A_K)/sqrtumax/sqrtumax)));
ktat = value_sqrt_0;
}

d_ltat_dV_A_K = (2.0*(twoatatoverthreebtat*d_sqrtumax_dV_A_K+d_twoatatoverthreebtat_dV_A_K*sqrtumax)-d_umax_dV_A_K);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);

d_mtat_dV_A_K = (((((model_.atatsti)*twoatatoverthreebtat)*d_sqrtumax_dV_A_K+(model_.atatsti)*d_twoatatoverthreebtat_dV_A_K*sqrtumax)-(model_.atatsti)*d_umax_dV_A_K)+0.5*(btat*d_umaxpoweronepointfive_dV_A_K+d_btat_dV_A_K*umaxpoweronepointfive));
mtat = (((((model_.atatsti)*twoatatoverthreebtat)*sqrtumax)-((model_.atatsti)*umax))+(0.5*(btat*umaxpoweronepointfive)));

d_xerfc_dV_A_K = ((ltat-1.0)*d_ktat_dV_A_K+d_ltat_dV_A_K*ktat);
xerfc = ((ltat-1.0)*ktat);

d_ysq_dV_A_K = (xerfc*d_xerfc_dV_A_K+d_xerfc_dV_A_K*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{

d_terfc_dV_A_K = (-(model_.perfc)*d_xerfc_dV_A_K/(1.0+((model_.perfc)*xerfc))/(1.0+((model_.perfc)*xerfc)));
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{

d_terfc_dV_A_K = (-(-(model_.perfc)*d_xerfc_dV_A_K)/(1.0-((model_.perfc)*xerfc))/(1.0-((model_.perfc)*xerfc)));
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;

d_tmp_dV_A_K = (deriv_exp_0_d0*(((-d_ysq_dV_A_K)+d_mtat_dV_A_K)));
tmp = value_exp_0;
}
}
else
{

d_tmp_dV_A_K = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dV_A_K)+d_mtat_dV_A_K))*3.3333333333333333e-01+(-((-d_ysq_dV_A_K)+d_mtat_dV_A_K))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dV_A_K)+d_mtat_dV_A_K))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}

d_erfcpos_dV_A_K = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*d_tmp_dV_A_K+((0.29214664*d_terfc_dV_A_K+(model_.berfc)*(terfc*d_terfc_dV_A_K+d_terfc_dV_A_K*terfc))+(model_.cerfc)*((terfc*terfc)*d_terfc_dV_A_K+(terfc*d_terfc_dV_A_K+d_terfc_dV_A_K*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{

d_erfctimesexpmtat_dV_A_K = d_erfcpos_dV_A_K;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;

d_tmp_dV_A_K = (deriv_exp_0_d0*(d_mtat_dV_A_K));
tmp = value_exp_0;
}
}
else
{

d_tmp_dV_A_K = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dV_A_K)*3.3333333333333333e-01+(-d_mtat_dV_A_K)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dV_A_K)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}

d_erfctimesexpmtat_dV_A_K = (2.0*d_tmp_dV_A_K-d_erfcpos_dV_A_K);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}

d_gammamax_dV_A_K = (1.77245385090551603*0.5)*((ktat*(model_.atatsti)*d_erfctimesexpmtat_dV_A_K-((model_.atatsti)*erfctimesexpmtat)*d_ktat_dV_A_K)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*(((model_.atatsti)*erfctimesexpmtat)/ktat));

d_itat_dV_A_K = (model_.CTATSTI_i)*((asrh*gammamax)*d_wtat_dV_A_K+(asrh*d_gammamax_dV_A_K+d_asrh_dV_A_K*gammamax)*wtat);
itat = ((model_.CTATSTI_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTSTI_i)==0.0))
{

d_ibbt_dV_A_K =  0.0;
ibbt = 0.0;
}
else
{
if (((model_.PSTI_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmp_dV_A_K = (deriv_sqrt_0_d0*((-d_vbbt_dV_A_K)*(model_.VBIRSTIinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)),(model_.PSTI_i));
double  deriv_pow_0_d0 = (((((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv)) == 0.0)?0.0:(value_pow_0*(model_.PSTI_i)/(((model_.VBIRSTI_i)-vbbt)*(model_.VBIRSTIinv))));

d_tmp_dV_A_K = (deriv_pow_0_d0*((-d_vbbt_dV_A_K)*(model_.VBIRSTIinv)));
tmp = value_pow_0;
}
}

d_Fmaxr_dV_A_K = (model_.one_over_one_minus_PSTI)*((tmp*(-d_vbbt_dV_A_K)*(model_.wdepnulrinvsti)-(((model_.VBIRSTI_i)-vbbt)*(model_.wdepnulrinvsti))*d_tmp_dV_A_K)/tmp/tmp);
Fmaxr = ((model_.one_over_one_minus_PSTI)*((((model_.VBIRSTI_i)-vbbt)*(model_.wdepnulrinvsti))/tmp));
if ((fabs(((-(model_.fbbtsti))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtsti))/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;

d_tmp_dV_A_K = (deriv_exp_0_d0*((-(-(model_.fbbtsti))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtsti))/Fmaxr)<0.0))
{

d_tmp_dV_A_K = (-1.0e-100*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(-(-(-(model_.fbbtsti))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-(-(-(model_.fbbtsti))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*3.3333333333333333e-01)))+(-(-(-(model_.fbbtsti))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtsti))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{

d_tmp_dV_A_K = 1.0e100*((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*0.5*((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(-(-(model_.fbbtsti))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)*3.3333333333333333e-01+(-(-(model_.fbbtsti))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+(-(-(model_.fbbtsti))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)*(1.0+(0.5*((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtsti))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}

d_ibbt_dV_A_K = (model_.CBBTSTI_i)*(((VAK*Fmaxr)*Fmaxr)*d_tmp_dV_A_K+((VAK*Fmaxr)*d_Fmaxr_dV_A_K+(VAK*d_Fmaxr_dV_A_K+d_VAK_dV_A_K*Fmaxr)*Fmaxr)*tmp);
ibbt = ((model_.CBBTSTI_i)*(((VAK*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRSTI_i)>1.0e3))
{

d_fbreakdown_dV_A_K =  0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRSTI_i))))
{
if (((model_.PBRSTI_i)==4.0))
{

d_tmp_dV_A_K = ((((vav*(model_.VBRinvsti))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)))*d_vav_dV_A_K*(model_.VBRinvsti)+(((vav*(model_.VBRinvsti))*(vav*(model_.VBRinvsti)))*d_vav_dV_A_K*(model_.VBRinvsti)+((vav*(model_.VBRinvsti))*d_vav_dV_A_K*(model_.VBRinvsti)+d_vav_dV_A_K*(model_.VBRinvsti)*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)));
tmp = ((((vav*(model_.VBRinvsti))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)))*(vav*(model_.VBRinvsti)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvsti)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRSTI_i));
double  deriv_fabs_0_d0 = ((((vav*(model_.VBRinvsti)))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*(model_.PBRSTI_i)/value_fabs_0));

d_tmp_dV_A_K = (deriv_pow_1_d0*((deriv_fabs_0_d0*(d_vav_dV_A_K*(model_.VBRinvsti)))));
tmp = value_pow_1;
}
}

d_fbreakdown_dV_A_K = (-(-d_tmp_dV_A_K)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{

d_fbreakdown_dV_A_K = d_vav_dV_A_K*(model_.slopesti);
fbreakdown = ((model_.fstopsti)+((vav+((model_.alphaav)*(model_.VBRSTI_i)))*(model_.slopesti)));
}
}

d_ijunsti_dV_A_K = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dV_A_K+(((d_id_dV_A_K+d_isrh_dV_A_K)+d_itat_dV_A_K)+d_ibbt_dV_A_K)*fbreakdown);
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((LG_i==0.0))
{

d_ijungat_dV_A_K =  0.0;
ijungat = 0.0;

d_qjungat_dV_A_K =  0.0;
qjungat = 0.0;
}
else
{
if (((model_.one_minus_PGAT)==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*(model_.vbiinvgat))));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmp_dV_A_K = (deriv_sqrt_0_d0*((-d_vj_dV_A_K*(model_.vbiinvgat))));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*(model_.vbiinvgat))),(model_.one_minus_PGAT));
double  deriv_pow_0_d0 = (((1.0-(vj*(model_.vbiinvgat))) == 0.0)?0.0:(value_pow_0*(model_.one_minus_PGAT)/(1.0-(vj*(model_.vbiinvgat)))));

d_tmp_dV_A_K = (deriv_pow_0_d0*((-d_vj_dV_A_K*(model_.vbiinvgat))));
tmp = value_pow_0;
}
}

d_qjungat_dV_A_K = ((model_.qprefgat)*(-d_tmp_dV_A_K)+(model_.qpref2gat)*(d_VAK_dV_A_K-d_vj_dV_A_K));
qjungat = (((model_.qprefgat)*(1.0-tmp))+((model_.qpref2gat)*(VAK-vj)));

d_id_dV_A_K = (model_.idsatgat)*d_idmult_dV_A_K;
id = ((model_.idsatgat)*idmult);
if ((((model_.CSRHGAT_i)==0.0)&&((model_.CTATGAT_i)==0.0)))
{

d_isrh_dV_A_K =  0.0;
isrh = 0.0;
}
else
{

d_vbi_minus_vjsrh_dV_A_K = (-d_vjsrh_dV_A_K);
vbi_minus_vjsrh = ((model_.vbigat)-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_wsrhstep_dV_A_K = (-(deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dV_A_K-two_psistar*d_vbi_minus_vjsrh_dV_A_K)/vbi_minus_vjsrh/vbi_minus_vjsrh)))));
wsrhstep = (1.0-value_sqrt_0);
}
if (((model_.PGAT_i)==0.5))
{

d_dwsrh_dV_A_K =  0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);

d_dwsrh_dV_A_K = ((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*(deriv_log_0_d0*(d_wsrhstep_dV_A_K))+(wsrhstep*d_wsrhstep_dV_A_K+d_wsrhstep_dV_A_K*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dV_A_K))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dV_A_K)*(1.0-(2.0*(model_.PGAT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*(model_.PGAT_i))));
}
}

d_wsrh_dV_A_K = (d_wsrhstep_dV_A_K+d_dwsrh_dV_A_K);
wsrh = (wsrhstep+dwsrh);
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*(model_.VBIRGATinv)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmp_dV_A_K = (deriv_sqrt_0_d0*(d_vbi_minus_vjsrh_dV_A_K*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*(model_.VBIRGATinv)),(model_.PGAT_i));
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*(model_.VBIRGATinv)) == 0.0)?0.0:(value_pow_0*(model_.PGAT_i)/(vbi_minus_vjsrh*(model_.VBIRGATinv))));

d_tmp_dV_A_K = (deriv_pow_0_d0*(d_vbi_minus_vjsrh_dV_A_K*(model_.VBIRGATinv)));
tmp = value_pow_0;
}
}

d_wdep_dV_A_K = (model_.wdepnulrgat)*d_tmp_dV_A_K;
wdep = ((model_.wdepnulrgat)*tmp);

d_asrh_dV_A_K = (model_.ftdgat)*((zinv-1.0)*d_wdep_dV_A_K+d_zinv_dV_A_K*wdep);
asrh = ((model_.ftdgat)*((zinv-1.0)*wdep));

d_isrh_dV_A_K = (model_.CSRHGAT_i)*(asrh*d_wsrh_dV_A_K+d_asrh_dV_A_K*wsrh);
isrh = ((model_.CSRHGAT_i)*(asrh*wsrh));
}
if (((model_.CTATGAT_i)==0.0))
{

d_itat_dV_A_K =  0.0;
itat = 0.0;
}
else
{

d_btat_dV_A_K = (model_.btatpartgat)*((vbi_minus_vjsrh*d_wdep_dV_A_K*(model_.one_minus_PGAT)-(wdep*(model_.one_minus_PGAT))*d_vbi_minus_vjsrh_dV_A_K)/vbi_minus_vjsrh/vbi_minus_vjsrh);
btat = ((model_.btatpartgat)*((wdep*(model_.one_minus_PGAT))/vbi_minus_vjsrh));

d_twoatatoverthreebtat_dV_A_K = (-(0.666666666666667*(model_.atatgat))*d_btat_dV_A_K/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*(model_.atatgat))/btat);

d_umaxbeforelimiting_dV_A_K = (twoatatoverthreebtat*d_twoatatoverthreebtat_dV_A_K+d_twoatatoverthreebtat_dV_A_K*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_umax_dV_A_K = (deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dV_A_K+d_umaxbeforelimiting_dV_A_K*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dV_A_K+d_umaxbeforelimiting_dV_A_K*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0))));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);

d_sqrtumax_dV_A_K = (deriv_sqrt_1_d0*((deriv_fabs_0_d0*(d_umax_dV_A_K))));
sqrtumax = value_sqrt_1;
}

d_umaxpoweronepointfive_dV_A_K = (umax*d_sqrtumax_dV_A_K+d_umax_dV_A_K*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT))==(-1.0)))
{

d_wgamma_dV_A_K = (-(btat*d_umaxpoweronepointfive_dV_A_K+d_btat_dV_A_K*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT)));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-(model_.PGAT_i))*(model_.one_over_one_minus_PGAT))/(1.0+(btat*umaxpoweronepointfive))));

d_wgamma_dV_A_K = (deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dV_A_K+d_btat_dV_A_K*umaxpoweronepointfive)));
wgamma = value_pow_0;
}
}

d_wtat_dV_A_K = (((wsrh+wgamma)*(wsrh*d_wgamma_dV_A_K+d_wsrh_dV_A_K*wgamma)-(wsrh*wgamma)*(d_wsrh_dV_A_K+d_wgamma_dV_A_K))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_ktat_dV_A_K = (deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dV_A_K-btat*d_sqrtumax_dV_A_K)/sqrtumax/sqrtumax)));
ktat = value_sqrt_0;
}

d_ltat_dV_A_K = (2.0*(twoatatoverthreebtat*d_sqrtumax_dV_A_K+d_twoatatoverthreebtat_dV_A_K*sqrtumax)-d_umax_dV_A_K);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);

d_mtat_dV_A_K = (((((model_.atatgat)*twoatatoverthreebtat)*d_sqrtumax_dV_A_K+(model_.atatgat)*d_twoatatoverthreebtat_dV_A_K*sqrtumax)-(model_.atatgat)*d_umax_dV_A_K)+0.5*(btat*d_umaxpoweronepointfive_dV_A_K+d_btat_dV_A_K*umaxpoweronepointfive));
mtat = (((((model_.atatgat)*twoatatoverthreebtat)*sqrtumax)-((model_.atatgat)*umax))+(0.5*(btat*umaxpoweronepointfive)));

d_xerfc_dV_A_K = ((ltat-1.0)*d_ktat_dV_A_K+d_ltat_dV_A_K*ktat);
xerfc = ((ltat-1.0)*ktat);

d_ysq_dV_A_K = (xerfc*d_xerfc_dV_A_K+d_xerfc_dV_A_K*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{

d_terfc_dV_A_K = (-(model_.perfc)*d_xerfc_dV_A_K/(1.0+((model_.perfc)*xerfc))/(1.0+((model_.perfc)*xerfc)));
terfc = (1.0/(1.0+((model_.perfc)*xerfc)));
}
else
{

d_terfc_dV_A_K = (-(-(model_.perfc)*d_xerfc_dV_A_K)/(1.0-((model_.perfc)*xerfc))/(1.0-((model_.perfc)*xerfc)));
terfc = (1.0/(1.0-((model_.perfc)*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;

d_tmp_dV_A_K = (deriv_exp_0_d0*(((-d_ysq_dV_A_K)+d_mtat_dV_A_K)));
tmp = value_exp_0;
}
}
else
{

d_tmp_dV_A_K = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dV_A_K)+d_mtat_dV_A_K))*3.3333333333333333e-01+(-((-d_ysq_dV_A_K)+d_mtat_dV_A_K))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dV_A_K)+d_mtat_dV_A_K))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}

d_erfcpos_dV_A_K = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*d_tmp_dV_A_K+((0.29214664*d_terfc_dV_A_K+(model_.berfc)*(terfc*d_terfc_dV_A_K+d_terfc_dV_A_K*terfc))+(model_.cerfc)*((terfc*terfc)*d_terfc_dV_A_K+(terfc*d_terfc_dV_A_K+d_terfc_dV_A_K*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+((model_.berfc)*(terfc*terfc)))+((model_.cerfc)*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{

d_erfctimesexpmtat_dV_A_K = d_erfcpos_dV_A_K;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;

d_tmp_dV_A_K = (deriv_exp_0_d0*(d_mtat_dV_A_K));
tmp = value_exp_0;
}
}
else
{

d_tmp_dV_A_K = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dV_A_K)*3.3333333333333333e-01+(-d_mtat_dV_A_K)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dV_A_K)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}

d_erfctimesexpmtat_dV_A_K = (2.0*d_tmp_dV_A_K-d_erfcpos_dV_A_K);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}

d_gammamax_dV_A_K = (1.77245385090551603*0.5)*((ktat*(model_.atatgat)*d_erfctimesexpmtat_dV_A_K-((model_.atatgat)*erfctimesexpmtat)*d_ktat_dV_A_K)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*(((model_.atatgat)*erfctimesexpmtat)/ktat));

d_itat_dV_A_K = (model_.CTATGAT_i)*((asrh*gammamax)*d_wtat_dV_A_K+(asrh*d_gammamax_dV_A_K+d_asrh_dV_A_K*gammamax)*wtat);
itat = ((model_.CTATGAT_i)*((asrh*gammamax)*wtat));
}
if (((model_.CBBTGAT_i)==0.0))
{

d_ibbt_dV_A_K =  0.0;
ibbt = 0.0;
}
else
{
if (((model_.PGAT_i)==0.5))
{
{
double value_sqrt_0 = sqrt((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);

d_tmp_dV_A_K = (deriv_sqrt_0_d0*((-d_vbbt_dV_A_K)*(model_.VBIRGATinv)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)),(model_.PGAT_i));
double  deriv_pow_0_d0 = (((((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv)) == 0.0)?0.0:(value_pow_0*(model_.PGAT_i)/(((model_.VBIRGAT_i)-vbbt)*(model_.VBIRGATinv))));

d_tmp_dV_A_K = (deriv_pow_0_d0*((-d_vbbt_dV_A_K)*(model_.VBIRGATinv)));
tmp = value_pow_0;
}
}

d_Fmaxr_dV_A_K = (model_.one_over_one_minus_PGAT)*((tmp*(-d_vbbt_dV_A_K)*(model_.wdepnulrinvgat)-(((model_.VBIRGAT_i)-vbbt)*(model_.wdepnulrinvgat))*d_tmp_dV_A_K)/tmp/tmp);
Fmaxr = ((model_.one_over_one_minus_PGAT)*((((model_.VBIRGAT_i)-vbbt)*(model_.wdepnulrinvgat))/tmp));
if ((fabs(((-(model_.fbbtgat))/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-(model_.fbbtgat))/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;

d_tmp_dV_A_K = (deriv_exp_0_d0*((-(-(model_.fbbtgat))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)));
tmp = value_exp_0;
}
}
else
{
if ((((-(model_.fbbtgat))/Fmaxr)<0.0))
{

d_tmp_dV_A_K = (-1.0e-100*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(-(-(-(model_.fbbtgat))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-(-(-(model_.fbbtgat))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*3.3333333333333333e-01)))+(-(-(-(model_.fbbtgat))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-(model_.fbbtgat))/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{

d_tmp_dV_A_K = 1.0e100*((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*0.5*((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(-(-(model_.fbbtgat))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)*3.3333333333333333e-01+(-(-(model_.fbbtgat))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+(-(-(model_.fbbtgat))*d_Fmaxr_dV_A_K/Fmaxr/Fmaxr)*(1.0+(0.5*((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-(model_.fbbtgat))/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}

d_ibbt_dV_A_K = (model_.CBBTGAT_i)*(((VAK*Fmaxr)*Fmaxr)*d_tmp_dV_A_K+((VAK*Fmaxr)*d_Fmaxr_dV_A_K+(VAK*d_Fmaxr_dV_A_K+d_VAK_dV_A_K*Fmaxr)*Fmaxr)*tmp);
ibbt = ((model_.CBBTGAT_i)*(((VAK*Fmaxr)*Fmaxr)*tmp));
}
if (((model_.VBRGAT_i)>1.0e3))
{

d_fbreakdown_dV_A_K =  0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-(model_.alphaav))*(model_.VBRGAT_i))))
{
if (((model_.PBRGAT_i)==4.0))
{

d_tmp_dV_A_K = ((((vav*(model_.VBRinvgat))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)))*d_vav_dV_A_K*(model_.VBRinvgat)+(((vav*(model_.VBRinvgat))*(vav*(model_.VBRinvgat)))*d_vav_dV_A_K*(model_.VBRinvgat)+((vav*(model_.VBRinvgat))*d_vav_dV_A_K*(model_.VBRinvgat)+d_vav_dV_A_K*(model_.VBRinvgat)*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)));
tmp = ((((vav*(model_.VBRinvgat))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)))*(vav*(model_.VBRinvgat)));
}
else
{
{
double value_fabs_0 = fabs((vav*(model_.VBRinvgat)));
double value_pow_1 = pow(value_fabs_0,(model_.PBRGAT_i));
double  deriv_fabs_0_d0 = ((((vav*(model_.VBRinvgat)))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*(model_.PBRGAT_i)/value_fabs_0));

d_tmp_dV_A_K = (deriv_pow_1_d0*((deriv_fabs_0_d0*(d_vav_dV_A_K*(model_.VBRinvgat)))));
tmp = value_pow_1;
}
}

d_fbreakdown_dV_A_K = (-(-d_tmp_dV_A_K)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{

d_fbreakdown_dV_A_K = d_vav_dV_A_K*(model_.slopegat);
fbreakdown = ((model_.fstopgat)+((vav+((model_.alphaav)*(model_.VBRGAT_i)))*(model_.slopegat)));
}
}

d_ijungat_dV_A_K = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dV_A_K+(((d_id_dV_A_K+d_isrh_dV_A_K)+d_itat_dV_A_K)+d_ibbt_dV_A_K)*fbreakdown);
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}

d_ijun_dV_A_K = ((AB_i*d_ijunbot_dV_A_K+LS_i*d_ijunsti_dV_A_K)+LG_i*d_ijungat_dV_A_K);
ijun = (((AB_i*ijunbot)+(LS_i*ijunsti))+(LG_i*ijungat));
}

d_qjun_dV_A_K = ((AB_i*d_qjunbot_dV_A_K+LS_i*d_qjunsti_dV_A_K)+LG_i*d_qjungat_dV_A_K);
qjun = (((AB_i*qjunbot)+(LS_i*qjunsti))+(LG_i*qjungat));
}
// End block evaluateStaticDynamic
//Begin block loadStatic
{
// I(A,K) <+ (((TYPE*MULT_i)*ijun))
staticContributions[admsNodeID_A] += (((model_.TYPE)*MULT_i)*ijun);
d_staticContributions[admsNodeID_A][admsProbeID_V_A_K] += ((model_.TYPE)*MULT_i)*d_ijun_dV_A_K;
staticContributions[admsNodeID_K] -= (((model_.TYPE)*MULT_i)*ijun);
d_staticContributions[admsNodeID_K][admsProbeID_V_A_K] -= ((model_.TYPE)*MULT_i)*d_ijun_dV_A_K;
}
// End block loadStatic
//Begin block loadDynamic
{
// I(A,K) <+ (ddt(((TYPE*MULT_i)*qjun)))
dynamicContributions[admsNodeID_A] += ((((model_.TYPE)*MULT_i)*qjun));
d_dynamicContributions[admsNodeID_A][admsProbeID_V_A_K] += (((model_.TYPE)*MULT_i)*d_qjun_dV_A_K);
dynamicContributions[admsNodeID_K] -= ((((model_.TYPE)*MULT_i)*qjun));
d_dynamicContributions[admsNodeID_K][admsProbeID_V_A_K] -= (((model_.TYPE)*MULT_i)*d_qjun_dV_A_K);
}
// End block loadDynamic
//Begin block noise
{
{
double value_fabs_0 = fabs(ijun);
double  deriv_fabs_0_d0 = (((ijun)>=0)?(+1.0):(-1.0));
jnoise = ((2*1.6021918E-19)*value_fabs_0);
}
// I(A,K) <+ (white_noise((MULT_i*jnoise),"shot"))
if (getSolverState().noiseFlag)
{
  noiseContribsPower[0]= (MULT_i*jnoise);
}
}
// End block noise
//Begin block OPinfo
{
vak = VAK;
cjbot = ((((model_.TYPE)*MULT_i)*AB_i)*(+d_qjunbot_dV_A_K));
cjgat = ((((model_.TYPE)*MULT_i)*LG_i)*(+d_qjungat_dV_A_K));
cjsti = ((((model_.TYPE)*MULT_i)*LS_i)*(+d_qjunsti_dV_A_K));
cj = ((cjbot+cjgat)+cjsti);
if (((model_.SWJUNEXP_i)==1.0))
{
ijbot = 0.0;
ijgat = 0.0;
ijsti = 0.0;
idsatsbot = 0.0;
idsatssti = 0.0;
idsatsgat = 0.0;
}
else
{
ijbot = ((MULT_i*AB_i)*ijunbot);
ijgat = ((MULT_i*LG_i)*ijungat);
ijsti = ((MULT_i*LS_i)*ijunsti);
idsatsbot = ((MULT_i*AB_i)*(model_.idsatbot));
idsatssti = ((MULT_i*LS_i)*(model_.idsatsti));
idsatsgat = ((MULT_i*LG_i)*(model_.idsatgat));
}
ij = (MULT_i*ijun);
si = (MULT_i*jnoise);
cjosbot = ((MULT_i*AB_i)*(model_.cjobot));
cjossti = ((MULT_i*LS_i)*(model_.cjosti));
cjosgat = ((MULT_i*LG_i)*(model_.cjogat));
vbisbot = (model_.vbibot);
vbissti = (model_.vbisti);
vbisgat = (model_.vbigat);
}
// End block OPinfo
}
// End block evaluateblock


  // -- endcode converted from analog/code block
  if (DEBUG_DEVICE && isActive(Diag::DEVICE_PARAMETERS) && getSolverState().debugTimeFlag)
  {
    Xyce::dout() << " probeVars[admsProbeID_V_A_GND] =  "
         <<probeVars[admsProbeID_V_A_GND] << std::endl;
    Xyce::dout() << " probeVars[admsProbeID_V_A_K] =  "
         <<probeVars[admsProbeID_V_A_K] << std::endl;
    Xyce::dout() << " staticContributions[admsNodeID_A] =  "
         <<staticContributions[admsNodeID_A] << std::endl;
      Xyce::dout() << "    staticContributions[admsNodeID_A].dx(admsProbeID_V_A_GND) =  " <<d_staticContributions[admsNodeID_A][admsProbeID_V_A_GND] << std::endl;
      Xyce::dout() << "    staticContributions[admsNodeID_A].dx(admsProbeID_V_A_K) =  " <<d_staticContributions[admsNodeID_A][admsProbeID_V_A_K] << std::endl;
    Xyce::dout() << " dynamicContributions[admsNodeID_A] =  "
         <<dynamicContributions[admsNodeID_A] << std::endl;
      Xyce::dout() << "    dynamicContributions[admsNodeID_A].dx(admsProbeID_V_A_GND) =  " <<d_dynamicContributions[admsNodeID_A][admsProbeID_V_A_GND] << std::endl;
      Xyce::dout() << "    dynamicContributions[admsNodeID_A].dx(admsProbeID_V_A_K) =  " <<d_dynamicContributions[admsNodeID_A][admsProbeID_V_A_K] << std::endl;
    Xyce::dout() << " staticContributions[admsNodeID_K] =  "
         <<staticContributions[admsNodeID_K] << std::endl;
      Xyce::dout() << "    staticContributions[admsNodeID_K].dx(admsProbeID_V_A_GND) =  " <<d_staticContributions[admsNodeID_K][admsProbeID_V_A_GND] << std::endl;
      Xyce::dout() << "    staticContributions[admsNodeID_K].dx(admsProbeID_V_A_K) =  " <<d_staticContributions[admsNodeID_K][admsProbeID_V_A_K] << std::endl;
    Xyce::dout() << " dynamicContributions[admsNodeID_K] =  "
         <<dynamicContributions[admsNodeID_K] << std::endl;
      Xyce::dout() << "    dynamicContributions[admsNodeID_K].dx(admsProbeID_V_A_GND) =  " <<d_dynamicContributions[admsNodeID_K][admsProbeID_V_A_GND] << std::endl;
      Xyce::dout() << "    dynamicContributions[admsNodeID_K].dx(admsProbeID_V_A_K) =  " <<d_dynamicContributions[admsNodeID_K][admsProbeID_V_A_K] << std::endl;

    if (!origFlag)
      Xyce::dout() << "This step was limited by this device." << std::endl;
  }


  if (loadLeadCurrent)
  {
    // If needed, we must now copy all the data from staticContributions
    // and dynamicContributionsinto the lead current F vector
    // Must make sure all collapsed node contributions get summed into the
    // external nodes properly.
    for ( int unmappedNode=0; unmappedNode < 2 ; unmappedNode++)
    {
      leadCurrentF[unmappedNode] = 0.0;
      leadCurrentQ[unmappedNode] = 0.0;
    }
    for ( int unmappedNode=0; unmappedNode < 2; unmappedNode++)
    {
      if (nodeMap[unmappedNode] < 2 && nodeMap[unmappedNode] != -1 )
      {
        leadCurrentF[nodeMap[unmappedNode]] += staticContributions[unmappedNode];
        leadCurrentQ[nodeMap[unmappedNode]] += dynamicContributions[unmappedNode];
      }
    }
  }
  return true;
}

//-----------------------------------------------------------------------------
// Function      : Instance::getNumNoiseSources
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
int Instance::getNumNoiseSources () const
{
return 1;
}

//-----------------------------------------------------------------------------
// Function      : Instance::setupNoiseSources
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
void Instance::setupNoiseSources (Xyce::Analysis::NoiseData & noiseData)
{
int numSources=getNumNoiseSources();
noiseData.numSources = numSources;
noiseData.resize(numSources);

noiseData.deviceName = getName().getEncodedName();
std::string theNoiseName;
theNoiseName = std::string("noise_")+getName().getEncodedName()+std::string("_white_A_K")+std::string("_")+std::string("shot");
std::replace(theNoiseName.begin(), theNoiseName.end(), ' ', '_');
noiseData.noiseNames[0]=theNoiseName;
noiseData.li_Pos[0]=li_A;
noiseData.li_Neg[0]=li_K;


}
//-----------------------------------------------------------------------------
// Function      : Instance::getNoiseSources
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
void Instance::getNoiseSources (Xyce::Analysis::NoiseData & noiseData)
{noiseData.noiseDens[0] = noiseContribsPower[0];
noiseData.lnNoiseDens[0] = std::log(std::max(noiseData.noiseDens[0],N_MINLOG));

}

//-----------------------------------------------------------------------------
// Function      : Instance::loadDAEdFdx
// Purpose       :
// Special Notes : Load the dFdx ("static jacobian") matrix
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
bool Instance::loadDAEdFdx()
{
  bool bsuccess = true;
  Linear::Matrix & dFdx = *(extData.dFdxMatrixPtr);

#ifndef Xyce_NONPOINTER_MATRIX_LOAD
  (*f_A_Equ_A_Node_Ptr) +=  +d_staticContributions[admsNodeID_A][admsProbeID_V_A_K];
  (*f_A_Equ_K_Node_Ptr) +=  -d_staticContributions[admsNodeID_A][admsProbeID_V_A_K];
  (*f_K_Equ_A_Node_Ptr) +=  +d_staticContributions[admsNodeID_K][admsProbeID_V_A_K];
  (*f_K_Equ_K_Node_Ptr) +=  -d_staticContributions[admsNodeID_K][admsProbeID_V_A_K];

#else
  //use the offsets instead of pointers
  dFdx[li_A][A_A_Equ_A_NodeOffset] +=  +d_staticContributions[admsNodeID_A][admsProbeID_V_A_K];
  dFdx[li_A][A_A_Equ_K_NodeOffset] +=  -d_staticContributions[admsNodeID_A][admsProbeID_V_A_K];
  dFdx[li_K][A_K_Equ_A_NodeOffset] +=  +d_staticContributions[admsNodeID_K][admsProbeID_V_A_K];
  dFdx[li_K][A_K_Equ_K_NodeOffset] +=  -d_staticContributions[admsNodeID_K][admsProbeID_V_A_K];

#endif

  return bsuccess;
}


//-----------------------------------------------------------------------------
// Function      : Instance::loadDAEdQdx
// Purpose       :
// Special Notes : Load the dQdx ("dynamic jacobian") matrix
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
bool Instance::loadDAEdQdx()
{
  bool bsuccess = true;
  Linear::Matrix & dQdx = *(extData.dQdxMatrixPtr);

#ifndef Xyce_NONPOINTER_MATRIX_LOAD
  (*q_A_Equ_A_Node_Ptr) +=  +d_dynamicContributions[admsNodeID_A][admsProbeID_V_A_K];
  (*q_A_Equ_K_Node_Ptr) +=  -d_dynamicContributions[admsNodeID_A][admsProbeID_V_A_K];
  (*q_K_Equ_A_Node_Ptr) +=  +d_dynamicContributions[admsNodeID_K][admsProbeID_V_A_K];
  (*q_K_Equ_K_Node_Ptr) +=  -d_dynamicContributions[admsNodeID_K][admsProbeID_V_A_K];

#else
  //use the offsets instead of pointers
  dQdx[li_A][A_A_Equ_A_NodeOffset] +=  +d_dynamicContributions[admsNodeID_A][admsProbeID_V_A_K];
  dQdx[li_A][A_A_Equ_K_NodeOffset] +=  -d_dynamicContributions[admsNodeID_A][admsProbeID_V_A_K];
  dQdx[li_K][A_K_Equ_A_NodeOffset] +=  +d_dynamicContributions[admsNodeID_K][admsProbeID_V_A_K];
  dQdx[li_K][A_K_Equ_K_NodeOffset] +=  -d_dynamicContributions[admsNodeID_K][admsProbeID_V_A_K];


#endif
  return bsuccess;
}




//-----------------------------------------------------------------------------
// Function      : Instance::updateTemperature
// Purpose       : Set temperature and update any parameters that depend on it
// Special Notes : In Xyce ADMS, we'll simply copy the temperature, which is
//                 in Kelvin, to our "admsTemperature" variable, which needs
//                 to be in Celsius.
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
bool Instance::updateTemperature(const double & temperatureTemp)
{

  admsTemperature = temperatureTemp;
  adms_vt_nom = adms_vt(temperatureTemp);

  return true;
}

// Class Model
//-----------------------------------------------------------------------------
// Function      : Model::processParams
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
bool Model::processParams()
{

  // Set any non-constant parameter defaults:
  // Set any parameters that were not given and whose defaults depend on other
  // parameters:



  // Now we need to check that any parameters are within their ranges as
  // specified in the verilog:

//    Parameter TYPE : [ (-1), 1 ]] 0, 0 [
  if ( (!((TYPE >=(-1) && TYPE <=1 )) || (TYPE >0 && TYPE <0 )) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter TYPE value " << TYPE << " out of range [ (-1), 1 ] or  ] 0, 0 [";
  }

//    Parameter IMAX : [ 1.0e-12,  (+inf) [
  if ( (!((IMAX >=1.0e-12))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter IMAX value " << IMAX << " out of range [ 1.0e-12,  (+inf) [";
  }

//    Parameter TRJ : [ (-2.5e2),  (+inf) [
  if ( (!((TRJ >=(-2.5e2)))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter TRJ value " << TRJ << " out of range [ (-2.5e2),  (+inf) [";
  }

//    Parameter FREV : [ 1.0e1, 1.0e10 ]
  if ( (!((FREV >=1.0e1 && FREV <=1.0e10 ))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter FREV value " << FREV << " out of range [ 1.0e1, 1.0e10 ]";
  }

//    Parameter CJORBOT : [ 1.0e-12,  (+inf) [
  if ( (!((CJORBOT >=1.0e-12))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CJORBOT value " << CJORBOT << " out of range [ 1.0e-12,  (+inf) [";
  }

//    Parameter CJORSTI : [ 1.0e-18,  (+inf) [
  if ( (!((CJORSTI >=1.0e-18))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CJORSTI value " << CJORSTI << " out of range [ 1.0e-18,  (+inf) [";
  }

//    Parameter CJORGAT : [ 1.0e-18,  (+inf) [
  if ( (!((CJORGAT >=1.0e-18))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CJORGAT value " << CJORGAT << " out of range [ 1.0e-18,  (+inf) [";
  }

//    Parameter VBIRBOT : [ 5.0e-2,  (+inf) [
  if ( (!((VBIRBOT >=5.0e-2))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter VBIRBOT value " << VBIRBOT << " out of range [ 5.0e-2,  (+inf) [";
  }

//    Parameter VBIRSTI : [ 5.0e-2,  (+inf) [
  if ( (!((VBIRSTI >=5.0e-2))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter VBIRSTI value " << VBIRSTI << " out of range [ 5.0e-2,  (+inf) [";
  }

//    Parameter VBIRGAT : [ 5.0e-2,  (+inf) [
  if ( (!((VBIRGAT >=5.0e-2))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter VBIRGAT value " << VBIRGAT << " out of range [ 5.0e-2,  (+inf) [";
  }

//    Parameter PBOT : [ 5.0e-2, 0.95 ]
  if ( (!((PBOT >=5.0e-2 && PBOT <=0.95 ))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter PBOT value " << PBOT << " out of range [ 5.0e-2, 0.95 ]";
  }

//    Parameter PSTI : [ 5.0e-2, 0.95 ]
  if ( (!((PSTI >=5.0e-2 && PSTI <=0.95 ))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter PSTI value " << PSTI << " out of range [ 5.0e-2, 0.95 ]";
  }

//    Parameter PGAT : [ 5.0e-2, 0.95 ]
  if ( (!((PGAT >=5.0e-2 && PGAT <=0.95 ))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter PGAT value " << PGAT << " out of range [ 5.0e-2, 0.95 ]";
  }

//    Parameter IDSATRBOT : [ 0.0,  (+inf) [
  if ( (!((IDSATRBOT >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter IDSATRBOT value " << IDSATRBOT << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter IDSATRSTI : [ 0.0,  (+inf) [
  if ( (!((IDSATRSTI >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter IDSATRSTI value " << IDSATRSTI << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter IDSATRGAT : [ 0.0,  (+inf) [
  if ( (!((IDSATRGAT >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter IDSATRGAT value " << IDSATRGAT << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter CSRHBOT : [ 0.0,  (+inf) [
  if ( (!((CSRHBOT >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CSRHBOT value " << CSRHBOT << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter CSRHSTI : [ 0.0,  (+inf) [
  if ( (!((CSRHSTI >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CSRHSTI value " << CSRHSTI << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter CSRHGAT : [ 0.0,  (+inf) [
  if ( (!((CSRHGAT >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CSRHGAT value " << CSRHGAT << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter XJUNSTI : [ 1.0e-9,  (+inf) [
  if ( (!((XJUNSTI >=1.0e-9))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter XJUNSTI value " << XJUNSTI << " out of range [ 1.0e-9,  (+inf) [";
  }

//    Parameter XJUNGAT : [ 1.0e-9,  (+inf) [
  if ( (!((XJUNGAT >=1.0e-9))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter XJUNGAT value " << XJUNGAT << " out of range [ 1.0e-9,  (+inf) [";
  }

//    Parameter CTATBOT : [ 0.0,  (+inf) [
  if ( (!((CTATBOT >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CTATBOT value " << CTATBOT << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter CTATSTI : [ 0.0,  (+inf) [
  if ( (!((CTATSTI >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CTATSTI value " << CTATSTI << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter CTATGAT : [ 0.0,  (+inf) [
  if ( (!((CTATGAT >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CTATGAT value " << CTATGAT << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter MEFFTATBOT : [ 1.0e-2,  (+inf) [
  if ( (!((MEFFTATBOT >=1.0e-2))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter MEFFTATBOT value " << MEFFTATBOT << " out of range [ 1.0e-2,  (+inf) [";
  }

//    Parameter MEFFTATSTI : [ 1.0e-2,  (+inf) [
  if ( (!((MEFFTATSTI >=1.0e-2))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter MEFFTATSTI value " << MEFFTATSTI << " out of range [ 1.0e-2,  (+inf) [";
  }

//    Parameter MEFFTATGAT : [ 1.0e-2,  (+inf) [
  if ( (!((MEFFTATGAT >=1.0e-2))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter MEFFTATGAT value " << MEFFTATGAT << " out of range [ 1.0e-2,  (+inf) [";
  }

//    Parameter CBBTBOT : [ 0.0,  (+inf) [
  if ( (!((CBBTBOT >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CBBTBOT value " << CBBTBOT << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter CBBTSTI : [ 0.0,  (+inf) [
  if ( (!((CBBTSTI >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CBBTSTI value " << CBBTSTI << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter CBBTGAT : [ 0.0,  (+inf) [
  if ( (!((CBBTGAT >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter CBBTGAT value " << CBBTGAT << " out of range [ 0.0,  (+inf) [";
  }

//    Parameter VBRBOT : [ 0.1,  (+inf) [
  if ( (!((VBRBOT >=0.1))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter VBRBOT value " << VBRBOT << " out of range [ 0.1,  (+inf) [";
  }

//    Parameter VBRSTI : [ 0.1,  (+inf) [
  if ( (!((VBRSTI >=0.1))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter VBRSTI value " << VBRSTI << " out of range [ 0.1,  (+inf) [";
  }

//    Parameter VBRGAT : [ 0.1,  (+inf) [
  if ( (!((VBRGAT >=0.1))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter VBRGAT value " << VBRGAT << " out of range [ 0.1,  (+inf) [";
  }

//    Parameter PBRBOT : [ 0.1,  (+inf) [
  if ( (!((PBRBOT >=0.1))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter PBRBOT value " << PBRBOT << " out of range [ 0.1,  (+inf) [";
  }

//    Parameter PBRSTI : [ 0.1,  (+inf) [
  if ( (!((PBRSTI >=0.1))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter PBRSTI value " << PBRSTI << " out of range [ 0.1,  (+inf) [";
  }

//    Parameter PBRGAT : [ 0.1,  (+inf) [
  if ( (!((PBRGAT >=0.1))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter PBRGAT value " << PBRGAT << " out of range [ 0.1,  (+inf) [";
  }

//    Parameter SWJUNEXP : [ 0.0, 1.0 ]
  if ( (!((SWJUNEXP >=0.0 && SWJUNEXP <=1.0 ))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter SWJUNEXP value " << SWJUNEXP << " out of range [ 0.0, 1.0 ]";
  }

//    Parameter VJUNREF : [ 0.5,  (+inf) [
  if ( (!((VJUNREF >=0.5))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter VJUNREF value " << VJUNREF << " out of range [ 0.5,  (+inf) [";
  }

//    Parameter FJUNQ : [ 0.0,  (+inf) [
  if ( (!((FJUNQ >=0.0))) )
  {
    UserWarning(*this) << "ADMSJUNCAP200: Parameter FJUNQ value " << FJUNQ << " out of range [ 0.0,  (+inf) [";
  }

  // and of course, this routine is where we should put the initial_model
  // stuff
  double deltaEgat=0.0;
  double deltaEsti=0.0;
  double deltaEbot=0.0;
  double ubigat=0.0;
  double ubisti=0.0;
  double ubibot=0.0;
  double phigdgat=0.0;
  double phigdsti=0.0;
  double phigdbot=0.0;
  double deltaphigd=0.0;
  double phigrgat=0.0;
  double phigrsti=0.0;
  double phigrbot=0.0;
  double deltaphigr=0.0;
  double phitrinv=0.0;
  double KBOL_over_QELE=0.0;
  double auxt=0.0;
  double tkd=0.0;
  double tkr=0.0;
  double STFBBTGAT_i=0.0;
  double STFBBTSTI_i=0.0;
  double STFBBTBOT_i=0.0;
  double FBBTRGAT_i=0.0;
  double FBBTRSTI_i=0.0;
  double FBBTRBOT_i=0.0;
  double MEFFTATGAT_i=0.0;
  double MEFFTATSTI_i=0.0;
  double MEFFTATBOT_i=0.0;
  double XJUNGAT_i=0.0;
  double XJUNSTI_i=0.0;
  double IDSATRGAT_i=0.0;
  double IDSATRSTI_i=0.0;
  double IDSATRBOT_i=0.0;
  double PHIGGAT_i=0.0;
  double PHIGSTI_i=0.0;
  double PHIGBOT_i=0.0;
  double CJORGAT_i=0.0;
  double CJORSTI_i=0.0;
  double CJORBOT_i=0.0;
  double FREV_i=0.0;
  double TRJ_i=0.0;
  double EPSSI=0.0;
//Begin block initial_model
{
EPSSI = (8.8541878176E-12*11.8);
TRJ_i = ((TRJ>(-2.5e2))?TRJ:(-2.5e2));
IMAX_i = ((IMAX>1.0e-12)?IMAX:1.0e-12);
FREV_i = ((FREV>1.0e1)?((FREV<1.0e10)?FREV:1.0e10):1.0e1);
CJORBOT_i = ((CJORBOT>1.0e-12)?CJORBOT:1.0e-12);
CJORSTI_i = ((CJORSTI>1.0e-18)?CJORSTI:1.0e-18);
CJORGAT_i = ((CJORGAT>1.0e-18)?CJORGAT:1.0e-18);
VBIRBOT_i = ((VBIRBOT>5.0e-2)?VBIRBOT:5.0e-2);
VBIRSTI_i = ((VBIRSTI>5.0e-2)?VBIRSTI:5.0e-2);
VBIRGAT_i = ((VBIRGAT>5.0e-2)?VBIRGAT:5.0e-2);
PBOT_i = ((PBOT>5.0e-2)?((PBOT<0.95)?PBOT:0.95):5.0e-2);
PSTI_i = ((PSTI>5.0e-2)?((PSTI<0.95)?PSTI:0.95):5.0e-2);
PGAT_i = ((PGAT>5.0e-2)?((PGAT<0.95)?PGAT:0.95):5.0e-2);
PHIGBOT_i = PHIGBOT;
PHIGSTI_i = PHIGSTI;
PHIGGAT_i = PHIGGAT;
IDSATRBOT_i = ((IDSATRBOT>0.0)?IDSATRBOT:0.0);
IDSATRSTI_i = ((IDSATRSTI>0.0)?IDSATRSTI:0.0);
IDSATRGAT_i = ((IDSATRGAT>0.0)?IDSATRGAT:0.0);
CSRHBOT_i = ((CSRHBOT>0.0)?CSRHBOT:0.0);
CSRHSTI_i = ((CSRHSTI>0.0)?CSRHSTI:0.0);
CSRHGAT_i = ((CSRHGAT>0.0)?CSRHGAT:0.0);
XJUNSTI_i = ((XJUNSTI>1.0e-9)?XJUNSTI:1.0e-9);
XJUNGAT_i = ((XJUNGAT>1.0e-9)?XJUNGAT:1.0e-9);
CTATBOT_i = ((CTATBOT>0.0)?CTATBOT:0.0);
CTATSTI_i = ((CTATSTI>0.0)?CTATSTI:0.0);
CTATGAT_i = ((CTATGAT>0.0)?CTATGAT:0.0);
MEFFTATBOT_i = ((MEFFTATBOT>1.0e-2)?MEFFTATBOT:1.0e-2);
MEFFTATSTI_i = ((MEFFTATSTI>1.0e-2)?MEFFTATSTI:1.0e-2);
MEFFTATGAT_i = ((MEFFTATGAT>1.0e-2)?MEFFTATGAT:1.0e-2);
CBBTBOT_i = ((CBBTBOT>0.0)?CBBTBOT:0.0);
CBBTSTI_i = ((CBBTSTI>0.0)?CBBTSTI:0.0);
CBBTGAT_i = ((CBBTGAT>0.0)?CBBTGAT:0.0);
FBBTRBOT_i = FBBTRBOT;
FBBTRSTI_i = FBBTRSTI;
FBBTRGAT_i = FBBTRGAT;
STFBBTBOT_i = STFBBTBOT;
STFBBTSTI_i = STFBBTSTI;
STFBBTGAT_i = STFBBTGAT;
VBRBOT_i = ((VBRBOT>0.1)?VBRBOT:0.1);
VBRSTI_i = ((VBRSTI>0.1)?VBRSTI:0.1);
VBRGAT_i = ((VBRGAT>0.1)?VBRGAT:0.1);
PBRBOT_i = ((PBRBOT>0.1)?PBRBOT:0.1);
PBRSTI_i = ((PBRSTI>0.1)?PBRSTI:0.1);
PBRGAT_i = ((PBRGAT>0.1)?PBRGAT:0.1);
SWJUNEXP_i = 0.0;
if ((SWJUNEXP>0.5))
{
SWJUNEXP_i = 1.0;
}
else
{
SWJUNEXP_i = 0.0;
}
VJUNREF_i = ((VJUNREF>0.5)?VJUNREF:0.5);
FJUNQ_i = ((FJUNQ>0.0)?FJUNQ:0.0);
tkr = (273.15+TRJ_i);
{
double value_max_0 = std::max((admsModTemp+DTA),(273.15+(-2.5e2)));
tkd = value_max_0;
}
auxt = (tkd/tkr);
KBOL_over_QELE = (1.3806505E-23/1.6021918E-19);
phitr = (KBOL_over_QELE*tkr);
phitrinv = (1.0/phitr);
phitd = (KBOL_over_QELE*tkd);
phitdinv = (1.0/phitd);
deltaphigr = ((-((7.02e-4*tkr)*tkr))/(1108.0+tkr));
phigrbot = (PHIGBOT_i+deltaphigr);
phigrsti = (PHIGSTI_i+deltaphigr);
phigrgat = (PHIGGAT_i+deltaphigr);
deltaphigd = ((-((7.02e-4*tkd)*tkd))/(1108.0+tkd));
phigdbot = (PHIGBOT_i+deltaphigd);
phigdsti = (PHIGSTI_i+deltaphigd);
phigdgat = (PHIGGAT_i+deltaphigd);
{
double value_pow_0 = pow(auxt,1.5);
double value_exp_1 = exp((0.5*((phigrbot*phitrinv)-(phigdbot*phitdinv))));
ftdbot = (value_pow_0*value_exp_1);
}
{
double value_pow_0 = pow(auxt,1.5);
double value_exp_1 = exp((0.5*((phigrsti*phitrinv)-(phigdsti*phitdinv))));
ftdsti = (value_pow_0*value_exp_1);
}
{
double value_pow_0 = pow(auxt,1.5);
double value_exp_1 = exp((0.5*((phigrgat*phitrinv)-(phigdgat*phitdinv))));
ftdgat = (value_pow_0*value_exp_1);
}
idsatbot = ((IDSATRBOT_i*ftdbot)*ftdbot);
idsatsti = ((IDSATRSTI_i*ftdsti)*ftdsti);
idsatgat = ((IDSATRGAT_i*ftdgat)*ftdgat);
{
double value_log_0 = log(ftdbot);
ubibot = ((VBIRBOT_i*auxt)-((2.0*phitd)*value_log_0));
}
{
double value_log_0 = log(ftdsti);
ubisti = ((VBIRSTI_i*auxt)-((2.0*phitd)*value_log_0));
}
{
double value_log_0 = log(ftdgat);
ubigat = ((VBIRGAT_i*auxt)-((2.0*phitd)*value_log_0));
}
{
double value_exp_0 = exp(((5.0e-2-ubibot)*phitdinv));
double value_log_1 = log((1+value_exp_0));
vbibot = (ubibot+(phitd*value_log_1));
}
{
double value_exp_0 = exp(((5.0e-2-ubisti)*phitdinv));
double value_log_1 = log((1+value_exp_0));
vbisti = (ubisti+(phitd*value_log_1));
}
{
double value_exp_0 = exp(((5.0e-2-ubigat)*phitdinv));
double value_log_1 = log((1+value_exp_0));
vbigat = (ubigat+(phitd*value_log_1));
}
vbiinvbot = (1.0/vbibot);
vbiinvsti = (1.0/vbisti);
vbiinvgat = (1.0/vbigat);
one_minus_PBOT = (1.0-PBOT_i);
one_minus_PSTI = (1.0-PSTI_i);
one_minus_PGAT = (1.0-PGAT_i);
one_over_one_minus_PBOT = (1.0/one_minus_PBOT);
one_over_one_minus_PSTI = (1.0/one_minus_PSTI);
one_over_one_minus_PGAT = (1.0/one_minus_PGAT);
{
double value_pow_0 = pow((VBIRBOT_i*vbiinvbot),PBOT_i);
cjobot = (CJORBOT_i*value_pow_0);
}
{
double value_pow_0 = pow((VBIRSTI_i*vbiinvsti),PSTI_i);
cjosti = (CJORSTI_i*value_pow_0);
}
{
double value_pow_0 = pow((VBIRGAT_i*vbiinvgat),PGAT_i);
cjogat = (CJORGAT_i*value_pow_0);
}
qprefbot = ((cjobot*vbibot)*one_over_one_minus_PBOT);
qprefsti = ((cjosti*vbisti)*one_over_one_minus_PSTI);
qprefgat = ((cjogat*vbigat)*one_over_one_minus_PGAT);
qpref2bot = (2.0*cjobot);
qpref2sti = (2.0*cjosti);
qpref2gat = (2.0*cjogat);
wdepnulrbot = (EPSSI/CJORBOT_i);
wdepnulrsti = ((XJUNSTI_i*EPSSI)/CJORSTI_i);
wdepnulrgat = ((XJUNGAT_i*EPSSI)/CJORGAT_i);
wdepnulrinvbot = (1.0/wdepnulrbot);
wdepnulrinvsti = (1.0/wdepnulrsti);
wdepnulrinvgat = (1.0/wdepnulrgat);
VBIRBOTinv = (1.0/VBIRBOT_i);
VBIRSTIinv = (1.0/VBIRSTI_i);
VBIRGATinv = (1.0/VBIRGAT_i);
perfc = (1.77245385090551603*0.29214664);
{
double value_pow_0 = pow(perfc,(-2.0));
berfc = (((((-5.0)*0.29214664)+6.0)-value_pow_0)/3.0);
}
cerfc = ((1.0-0.29214664)-berfc);
{
double value_max_0 = std::max((0.5*phigdbot),phitd);
deltaEbot = value_max_0;
}
{
double value_max_0 = std::max((0.5*phigdsti),phitd);
deltaEsti = value_max_0;
}
{
double value_max_0 = std::max((0.5*phigdgat),phitd);
deltaEgat = value_max_0;
}
atatbot = (deltaEbot*phitdinv);
atatsti = (deltaEsti*phitdinv);
atatgat = (deltaEgat*phitdinv);
{
double value_sqrt_0 = sqrt(((((32.0*MEFFTATBOT_i)*9.1093826E-31)*1.6021918E-19)*((deltaEbot*deltaEbot)*deltaEbot)));
btatpartbot = (value_sqrt_0/(3.0*1.05457168E-34));
}
{
double value_sqrt_0 = sqrt(((((32.0*MEFFTATSTI_i)*9.1093826E-31)*1.6021918E-19)*((deltaEsti*deltaEsti)*deltaEsti)));
btatpartsti = (value_sqrt_0/(3.0*1.05457168E-34));
}
{
double value_sqrt_0 = sqrt(((((32.0*MEFFTATGAT_i)*9.1093826E-31)*1.6021918E-19)*((deltaEgat*deltaEgat)*deltaEgat)));
btatpartgat = (value_sqrt_0/(3.0*1.05457168E-34));
}
fbbtbot = (FBBTRBOT_i*(1.0+(STFBBTBOT_i*(tkd-tkr))));
fbbtsti = (FBBTRSTI_i*(1.0+(STFBBTSTI_i*(tkd-tkr))));
fbbtgat = (FBBTRGAT_i*(1.0+(STFBBTGAT_i*(tkd-tkr))));
fbbtbot = ((fbbtbot>0.0)?fbbtbot:0.0);
fbbtsti = ((fbbtsti>0.0)?fbbtsti:0.0);
fbbtgat = ((fbbtgat>0.0)?fbbtgat:0.0);
alphaav = (1.0-(1.0/FREV_i));
{
double value_pow_0 = pow(alphaav,PBRBOT_i);
fstopbot = (1.0/(1.0-value_pow_0));
}
{
double value_pow_0 = pow(alphaav,PBRSTI_i);
fstopsti = (1.0/(1.0-value_pow_0));
}
{
double value_pow_0 = pow(alphaav,PBRGAT_i);
fstopgat = (1.0/(1.0-value_pow_0));
}
VBRinvbot = (1.0/VBRBOT_i);
VBRinvsti = (1.0/VBRSTI_i);
VBRinvgat = (1.0/VBRGAT_i);
{
double value_pow_0 = pow(alphaav,(PBRBOT_i-1.0));
slopebot = (((-((fstopbot*fstopbot)*value_pow_0))*PBRBOT_i)*VBRinvbot);
}
{
double value_pow_0 = pow(alphaav,(PBRSTI_i-1.0));
slopesti = (((-((fstopsti*fstopsti)*value_pow_0))*PBRSTI_i)*VBRinvsti);
}
{
double value_pow_0 = pow(alphaav,(PBRGAT_i-1.0));
slopegat = (((-((fstopgat*fstopgat)*value_pow_0))*PBRGAT_i)*VBRinvgat);
}
}
// End block initial_model


  return true;
}
//----------------------------------------------------------------------------
// Function      : Model::processInstanceParams
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       :
// Creation Date :
//----------------------------------------------------------------------------
bool Model::processInstanceParams()
{

  std::vector<Instance*>::iterator iter;
  std::vector<Instance*>::iterator first = instanceContainer.begin();
  std::vector<Instance*>::iterator last  = instanceContainer.end();

  for (iter=first; iter!=last; ++iter)
  {
    (*iter)->processParams();
  }

  return true;
}

//-----------------------------------------------------------------------------
// Function      : Model::Model
// Purpose       : model block constructor
// Special Notes :
// Scope         : public
// Creator       :
// Creation Date :
//-----------------------------------------------------------------------------
Model::Model(
  const Configuration & configuration,
  const ModelBlock &    model_block,
  const FactoryBlock &  factory_block)
  : DeviceModel(model_block, configuration.getModelParameters(), factory_block),
    LEVEL(200),
    TYPE(1.0),
    DTA(0.0),
    IMAX(1000.0),
    TRJ(21.0),
    FREV(1.0e3),
    CJORBOT(1.0e-3),
    CJORSTI(1.0e-9),
    CJORGAT(1.0e-9),
    VBIRBOT(1.0),
    VBIRSTI(1.0),
    VBIRGAT(1.0),
    PBOT(0.5),
    PSTI(0.5),
    PGAT(0.5),
    PHIGBOT(1.16),
    PHIGSTI(1.16),
    PHIGGAT(1.16),
    IDSATRBOT(1.0e-12),
    IDSATRSTI(1.0e-18),
    IDSATRGAT(1.0e-18),
    CSRHBOT(1.0e2),
    CSRHSTI(1.0e-4),
    CSRHGAT(1.0e-4),
    XJUNSTI(1.0e-7),
    XJUNGAT(1.0e-7),
    CTATBOT(1.0e2),
    CTATSTI(1.0e-4),
    CTATGAT(1.0e-4),
    MEFFTATBOT(0.25),
    MEFFTATSTI(0.25),
    MEFFTATGAT(0.25),
    CBBTBOT(1.0e-12),
    CBBTSTI(1.0e-18),
    CBBTGAT(1.0e-18),
    FBBTRBOT(1.0e9),
    FBBTRSTI(1.0e9),
    FBBTRGAT(1.0e9),
    STFBBTBOT((-1.0e-3)),
    STFBBTSTI((-1.0e-3)),
    STFBBTGAT((-1.0e-3)),
    VBRBOT(10.0),
    VBRSTI(10.0),
    VBRGAT(10.0),
    PBRBOT(4.0),
    PBRSTI(4.0),
    PBRGAT(4.0),
    SWJUNEXP(0.0),
    VJUNREF(2.5),
    FJUNQ(0.03),
    IMAX_i(0.0),
    VBIRBOT_i(0.0),
    VBIRSTI_i(0.0),
    VBIRGAT_i(0.0),
    PBOT_i(0.0),
    PSTI_i(0.0),
    PGAT_i(0.0),
    CSRHBOT_i(0.0),
    CSRHSTI_i(0.0),
    CSRHGAT_i(0.0),
    CTATBOT_i(0.0),
    CTATSTI_i(0.0),
    CTATGAT_i(0.0),
    CBBTBOT_i(0.0),
    CBBTSTI_i(0.0),
    CBBTGAT_i(0.0),
    VBRBOT_i(0.0),
    VBRSTI_i(0.0),
    VBRGAT_i(0.0),
    PBRBOT_i(0.0),
    PBRSTI_i(0.0),
    PBRGAT_i(0.0),
    SWJUNEXP_i(0.0),
    VJUNREF_i(0.0),
    FJUNQ_i(0.0),
    phitr(0.0),
    phitd(0.0),
    phitdinv(0.0),
    perfc(0.0),
    berfc(0.0),
    cerfc(0.0),
    ftdbot(0.0),
    ftdsti(0.0),
    ftdgat(0.0),
    idsatbot(0.0),
    idsatsti(0.0),
    idsatgat(0.0),
    vbibot(0.0),
    vbisti(0.0),
    vbigat(0.0),
    vbiinvbot(0.0),
    vbiinvsti(0.0),
    vbiinvgat(0.0),
    one_minus_PBOT(0.0),
    one_minus_PSTI(0.0),
    one_minus_PGAT(0.0),
    one_over_one_minus_PBOT(0.0),
    one_over_one_minus_PSTI(0.0),
    one_over_one_minus_PGAT(0.0),
    cjobot(0.0),
    cjosti(0.0),
    cjogat(0.0),
    qprefbot(0.0),
    qprefsti(0.0),
    qprefgat(0.0),
    qpref2bot(0.0),
    qpref2sti(0.0),
    qpref2gat(0.0),
    wdepnulrbot(0.0),
    wdepnulrsti(0.0),
    wdepnulrgat(0.0),
    wdepnulrinvbot(0.0),
    wdepnulrinvsti(0.0),
    wdepnulrinvgat(0.0),
    VBIRBOTinv(0.0),
    VBIRSTIinv(0.0),
    VBIRGATinv(0.0),
    atatbot(0.0),
    atatsti(0.0),
    atatgat(0.0),
    btatpartbot(0.0),
    btatpartsti(0.0),
    btatpartgat(0.0),
    fbbtbot(0.0),
    fbbtsti(0.0),
    fbbtgat(0.0),
    alphaav(0.0),
    fstopbot(0.0),
    fstopsti(0.0),
    fstopgat(0.0),
    VBRinvbot(0.0),
    VBRinvsti(0.0),
    VBRinvgat(0.0),
    slopebot(0.0),
    slopesti(0.0),
    slopegat(0.0)
{
  // Set params to constant default values (from parTable):
  setDefaultParams();

  // Set params according to .model line and constant defaults from metadata:
  setModParams(model_block.params);

  if (!given("XYCEADMSMODTEMP"))
    admsModTemp=getDeviceOptions().temp.getImmutableValue<double>();

  // Calculate any parameters specified as expressions:

  updateDependentParameters();

  // calculate dependent (ie computed) params and check for errors:
  processParams();
}

//-----------------------------------------------------------------------------
// Function      : Model::~Model
// Purpose       : destructor
// Special Notes :
// Scope         : public
// Creator       :
// Creation Date :
//-----------------------------------------------------------------------------
Model::~Model()
{
  std::vector<Instance*>::iterator iterI;
  std::vector<Instance*>::iterator firstI = instanceContainer.begin ();
  std::vector<Instance*>::iterator lastI  = instanceContainer.end ();

  // loop over instances:
  for (iterI = firstI; iterI != lastI; ++iterI)
  {
    delete (*iterI);
  }
}

//-----------------------------------------------------------------------------
// Function      : Model::printOutInstances
// Purpose       : debugging tool.
// Special Notes :
// Scope         : public
// Creator       :
// Creation Date :
//-----------------------------------------------------------------------------
std::ostream &Model::printOutInstances(std::ostream &os) const
{
  std::vector<Instance*>::const_iterator iter;
  std::vector<Instance*>::const_iterator first = instanceContainer.begin();
  std::vector<Instance*>::const_iterator last  = instanceContainer.end();

  int i;
  os << std::endl;
  os << "    name     model name  Parameters" << std::endl;
  for (i=0, iter=first; iter!=last; ++iter, ++i)
  {
    os << "  " << i << ": " << (*iter)->getName() << "      ";
    os << getName();

    os << std::endl;
      os << "AB  =  " << (*iter)->AB << std::endl;
      os << "LS  =  " << (*iter)->LS << std::endl;
      os << "LG  =  " << (*iter)->LG << std::endl;
      os << "MULT  =  " << (*iter)->MULT << std::endl;
    os << std::endl;
  }

  os << std::endl;

  return os;
}

//-----------------------------------------------------------------------------
// Function      : Model::forEachInstance
// Purpose       :
// Special Notes :
// Scope         : public
// Creator       : David Baur
// Creation Date : 2/4/2014
//-----------------------------------------------------------------------------
/// Apply a device instance "op" to all instances associated with this
/// model
///
/// @param[in] op Operator to apply to all instances.
///
///
void Model::forEachInstance(DeviceInstanceOp &op) const
{
  for (std::vector<Instance *>::const_iterator it = instanceContainer.begin(); it != instanceContainer.end(); ++it)
    op(*it);
}

Device *Traits::factory(const Configuration &configuration, const FactoryBlock &factory_block)
{
  return new DeviceMaster<Traits>(configuration, factory_block, factory_block.solverState_, factory_block.deviceOptions_);
}

void
registerDevice(const DeviceCountMap& deviceMap, const std::set<int>& levelSet)
{
if (deviceMap.empty() ||
((deviceMap.find("D") != deviceMap.end() && (levelSet.find(200)!=levelSet.end()))))
{
Diode::registerDevice();

  Config<Traits>::addConfiguration()
    .registerDevice("d", 200)
    .registerModelType("d", 200);
}
}


#ifdef Xyce_ADMS_SENSITIVITIES
//-----------------------------------------------------------------------------
// Function      : evaluateInitialInstance
// Purpose       : Evaluate the statements in the initial_instance block
// Special Notes : specific for sensitivity use
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
void evaluateInitialInstance(
instanceSensStruct & instanceStruct,
modelSensStruct & modelStruct,
 double admsTemperature, double adms_vt_nom, double ADMSgmin_arg, const Instance & theInstance)
{
  double I5=0.0;
double d_I5_dX=0.0;
  double I4=0.0;
double d_I4_dX=0.0;
  double I3=0.0;
double d_I3_dX=0.0;
  double I2=0.0;
double d_I2_dX=0.0;
  double I1=0.0;
double d_I1_dX=0.0;
  double V5=0.0;
  double V4=0.0;
  double V3=0.0;
double d_V3_dX=0.0;
  double V2=0.0;
double d_V2_dX=0.0;
  double V1=0.0;
double d_V1_dX=0.0;
  double FRACI=0.0;
  double FRACNB=0.0;
  double FRACNA=0.0;
  double alphaje=0.0;
double d_alphaje_dX=0.0;
  double zfrac=0.0;
double d_zfrac_dX=0.0;
  double tt2=0.0;
double d_tt2_dX=0.0;
  double tt1=0.0;
double d_tt1_dX=0.0;
  double tt0=0.0;
double d_tt0_dX=0.0;
  double I5_cor=0.0;
double d_I5_cor_dX=0.0;
  double I4_cor=0.0;
double d_I4_cor_dX=0.0;
  double I3_cor=0.0;
double d_I3_cor_dX=0.0;
  double I2_cor=0.0;
double d_I2_cor_dX=0.0;
  double I1_cor=0.0;
double d_I1_cor_dX=0.0;
  double mcor_rev=0.0;
double d_mcor_rev_dX=0.0;
  double m0_rev=0.0;
double d_m0_rev_dX=0.0;
  double pmax=0.0;
double d_pmax_dX=0.0;
  double vbigat2r=0.0;
double d_vbigat2r_dX=0.0;
  double vbisti2r=0.0;
double d_vbisti2r_dX=0.0;
  double vbibot2r=0.0;
double d_vbibot2r_dX=0.0;
  double pgat2=0.0;
double d_pgat2_dX=0.0;
  double psti2=0.0;
double d_psti2_dX=0.0;
  double pbot2=0.0;
double d_pbot2_dX=0.0;
  double vbigat2=0.0;
double d_vbigat2_dX=0.0;
  double vbisti2=0.0;
double d_vbisti2_dX=0.0;
  double vbibot2=0.0;
double d_vbibot2_dX=0.0;
  double vmaxgat=0.0;
double d_vmaxgat_dX=0.0;
  double vmaxsti=0.0;
double d_vmaxsti_dX=0.0;
  double vmaxbot=0.0;
double d_vmaxbot_dX=0.0;
//Begin block initial_instance
{
instanceStruct.d_instanceVar_AB_i_dX = ((instanceStruct.instancePar_AB>0.0)?instanceStruct.d_instancePar_AB_dX:0.0);
instanceStruct.instanceVar_AB_i = ((instanceStruct.instancePar_AB>0.0)?instanceStruct.instancePar_AB:0.0);
instanceStruct.d_instanceVar_LS_i_dX = ((instanceStruct.instancePar_LS>0.0)?instanceStruct.d_instancePar_LS_dX:0.0);
instanceStruct.instanceVar_LS_i = ((instanceStruct.instancePar_LS>0.0)?instanceStruct.instancePar_LS:0.0);
instanceStruct.d_instanceVar_LG_i_dX = ((instanceStruct.instancePar_LG>0.0)?instanceStruct.d_instancePar_LG_dX:0.0);
instanceStruct.instanceVar_LG_i = ((instanceStruct.instancePar_LG>0.0)?instanceStruct.instancePar_LG:0.0);
instanceStruct.d_instanceVar_MULT_i_dX = ((instanceStruct.instancePar_MULT>0.0)?instanceStruct.d_instancePar_MULT_dX:0.0);
instanceStruct.instanceVar_MULT_i = ((instanceStruct.instancePar_MULT>0.0)?instanceStruct.instancePar_MULT:0.0);
instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX = 0.0;
instanceStruct.instanceVar_exp_VMAX_over_phitd = 0.0;
if (((modelStruct.modelVar_idsatbot*instanceStruct.instanceVar_AB_i)>0.0))
{
{
double value_log_0 = log(((modelStruct.modelVar_IMAX_i/(modelStruct.modelVar_idsatbot*instanceStruct.instanceVar_AB_i))+1.0));
double  deriv_log_0_d0 = (1.0/((modelStruct.modelVar_IMAX_i/(modelStruct.modelVar_idsatbot*instanceStruct.instanceVar_AB_i))+1.0));
d_vmaxbot_dX = (modelStruct.modelVar_phitd*deriv_log_0_d0*((((modelStruct.modelVar_idsatbot*instanceStruct.instanceVar_AB_i)*modelStruct.d_modelVar_IMAX_i_dX-modelStruct.modelVar_IMAX_i*(modelStruct.modelVar_idsatbot*instanceStruct.d_instanceVar_AB_i_dX+modelStruct.d_modelVar_idsatbot_dX*instanceStruct.instanceVar_AB_i))/(modelStruct.modelVar_idsatbot*instanceStruct.instanceVar_AB_i)/(modelStruct.modelVar_idsatbot*instanceStruct.instanceVar_AB_i)))+modelStruct.d_modelVar_phitd_dX*value_log_0);
vmaxbot = (modelStruct.modelVar_phitd*value_log_0);
}
}
else
{
d_vmaxbot_dX = 0.0;
vmaxbot = 1.0e8;
}
if (((modelStruct.modelVar_idsatsti*instanceStruct.instanceVar_LS_i)>0.0))
{
{
double value_log_0 = log(((modelStruct.modelVar_IMAX_i/(modelStruct.modelVar_idsatsti*instanceStruct.instanceVar_LS_i))+1.0));
double  deriv_log_0_d0 = (1.0/((modelStruct.modelVar_IMAX_i/(modelStruct.modelVar_idsatsti*instanceStruct.instanceVar_LS_i))+1.0));
d_vmaxsti_dX = (modelStruct.modelVar_phitd*deriv_log_0_d0*((((modelStruct.modelVar_idsatsti*instanceStruct.instanceVar_LS_i)*modelStruct.d_modelVar_IMAX_i_dX-modelStruct.modelVar_IMAX_i*(modelStruct.modelVar_idsatsti*instanceStruct.d_instanceVar_LS_i_dX+modelStruct.d_modelVar_idsatsti_dX*instanceStruct.instanceVar_LS_i))/(modelStruct.modelVar_idsatsti*instanceStruct.instanceVar_LS_i)/(modelStruct.modelVar_idsatsti*instanceStruct.instanceVar_LS_i)))+modelStruct.d_modelVar_phitd_dX*value_log_0);
vmaxsti = (modelStruct.modelVar_phitd*value_log_0);
}
}
else
{
d_vmaxsti_dX = 0.0;
vmaxsti = 1.0e8;
}
if (((modelStruct.modelVar_idsatgat*instanceStruct.instanceVar_LG_i)>0.0))
{
{
double value_log_0 = log(((modelStruct.modelVar_IMAX_i/(modelStruct.modelVar_idsatgat*instanceStruct.instanceVar_LG_i))+1.0));
double  deriv_log_0_d0 = (1.0/((modelStruct.modelVar_IMAX_i/(modelStruct.modelVar_idsatgat*instanceStruct.instanceVar_LG_i))+1.0));
d_vmaxgat_dX = (modelStruct.modelVar_phitd*deriv_log_0_d0*((((modelStruct.modelVar_idsatgat*instanceStruct.instanceVar_LG_i)*modelStruct.d_modelVar_IMAX_i_dX-modelStruct.modelVar_IMAX_i*(modelStruct.modelVar_idsatgat*instanceStruct.d_instanceVar_LG_i_dX+modelStruct.d_modelVar_idsatgat_dX*instanceStruct.instanceVar_LG_i))/(modelStruct.modelVar_idsatgat*instanceStruct.instanceVar_LG_i)/(modelStruct.modelVar_idsatgat*instanceStruct.instanceVar_LG_i)))+modelStruct.d_modelVar_phitd_dX*value_log_0);
vmaxgat = (modelStruct.modelVar_phitd*value_log_0);
}
}
else
{
d_vmaxgat_dX = 0.0;
vmaxgat = 1.0e8;
}
{
double value_min_0 = std::min(vmaxbot,vmaxsti);
double value_min_1 = std::min(std::min(vmaxbot,vmaxsti),vmaxgat);
double  deriv_min_0_d0 = ((vmaxbot<=vmaxsti)?1.0:0.0);
double  deriv_min_0_d1 = ((vmaxbot<=vmaxsti)?0.0:1.0);
double  deriv_min_1_d0 = ((std::min(vmaxbot,vmaxsti)<=vmaxgat)?1.0:0.0);
double  deriv_min_1_d1 = ((std::min(vmaxbot,vmaxsti)<=vmaxgat)?0.0:1.0);
instanceStruct.d_instanceVar_VMAX_dX = 0.0;
instanceStruct.instanceVar_VMAX = std::min(std::min(vmaxbot,vmaxsti),vmaxgat);
}
if ((fabs((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv));
double  deriv_exp_0_d0 = value_exp_0;
instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX = deriv_exp_0_d0*((instanceStruct.instanceVar_VMAX*modelStruct.d_modelVar_phitdinv_dX+instanceStruct.d_instanceVar_VMAX_dX*modelStruct.modelVar_phitdinv));
instanceStruct.instanceVar_exp_VMAX_over_phitd = value_exp_0;
}
}
else
{
if (((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv)<0.0))
{
instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX = (-1.0e-100*(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*0.5*(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*(-(instanceStruct.instanceVar_VMAX*modelStruct.d_modelVar_phitdinv_dX+instanceStruct.d_instanceVar_VMAX_dX*modelStruct.modelVar_phitdinv))*3.3333333333333333e-01+(-(instanceStruct.instanceVar_VMAX*modelStruct.d_modelVar_phitdinv_dX+instanceStruct.d_instanceVar_VMAX_dX*modelStruct.modelVar_phitdinv))*(1.0+(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*3.3333333333333333e-01)))+(-(instanceStruct.instanceVar_VMAX*modelStruct.d_modelVar_phitdinv_dX+instanceStruct.d_instanceVar_VMAX_dX*modelStruct.modelVar_phitdinv))*(1.0+(0.5*(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*(1.0+(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*(1.0+(0.5*(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*(1.0+(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*(1.0+(0.5*(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*(1.0+(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*3.3333333333333333e-01))))))));
instanceStruct.instanceVar_exp_VMAX_over_phitd = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*(1.0+(0.5*(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*(1.0+(((-2.3025850929940458e+02)-(instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv))*3.3333333333333333e-01))))))));
}
else
{
instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX = 1.0e100*(((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv)-2.3025850929940458e+02)*0.5*(((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv)-2.3025850929940458e+02)*(instanceStruct.instanceVar_VMAX*modelStruct.d_modelVar_phitdinv_dX+instanceStruct.d_instanceVar_VMAX_dX*modelStruct.modelVar_phitdinv)*3.3333333333333333e-01+(instanceStruct.instanceVar_VMAX*modelStruct.d_modelVar_phitdinv_dX+instanceStruct.d_instanceVar_VMAX_dX*modelStruct.modelVar_phitdinv)*(1.0+(((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv)-2.3025850929940458e+02)*3.3333333333333333e-01)))+(instanceStruct.instanceVar_VMAX*modelStruct.d_modelVar_phitdinv_dX+instanceStruct.d_instanceVar_VMAX_dX*modelStruct.modelVar_phitdinv)*(1.0+(0.5*(((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv)-2.3025850929940458e+02)*(1.0+(((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
instanceStruct.instanceVar_exp_VMAX_over_phitd = (1.0e100*(1.0+(((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv)-2.3025850929940458e+02)*(1.0+(0.5*(((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv)-2.3025850929940458e+02)*(1.0+(((instanceStruct.instanceVar_VMAX*modelStruct.modelVar_phitdinv)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_vbibot2_dX = modelStruct.d_modelVar_vbibot_dX;
vbibot2 = modelStruct.modelVar_vbibot;
d_vbisti2_dX = modelStruct.d_modelVar_vbisti_dX;
vbisti2 = modelStruct.modelVar_vbisti;
d_vbigat2_dX = modelStruct.d_modelVar_vbigat_dX;
vbigat2 = modelStruct.modelVar_vbigat;
d_pbot2_dX = modelStruct.d_modelVar_PBOT_i_dX;
pbot2 = modelStruct.modelVar_PBOT_i;
d_psti2_dX = modelStruct.d_modelVar_PSTI_i_dX;
psti2 = modelStruct.modelVar_PSTI_i;
d_pgat2_dX = modelStruct.d_modelVar_PGAT_i_dX;
pgat2 = modelStruct.modelVar_PGAT_i;
d_vbibot2r_dX = modelStruct.d_modelVar_VBIRBOT_i_dX;
vbibot2r = modelStruct.modelVar_VBIRBOT_i;
d_vbisti2r_dX = modelStruct.d_modelVar_VBIRSTI_i_dX;
vbisti2r = modelStruct.modelVar_VBIRSTI_i;
d_vbigat2r_dX = modelStruct.d_modelVar_VBIRGAT_i_dX;
vbigat2r = modelStruct.modelVar_VBIRGAT_i;
if ((instanceStruct.instanceVar_AB_i==0.0))
{
d_vbibot2_dX = (modelStruct.d_modelVar_vbisti_dX+modelStruct.d_modelVar_vbigat_dX);
vbibot2 = (modelStruct.modelVar_vbisti+modelStruct.modelVar_vbigat);
{
double value_min_0 = std::min(modelStruct.modelVar_PSTI_i,modelStruct.modelVar_PGAT_i);
double  deriv_min_0_d0 = ((modelStruct.modelVar_PSTI_i<=modelStruct.modelVar_PGAT_i)?1.0:0.0);
double  deriv_min_0_d1 = ((modelStruct.modelVar_PSTI_i<=modelStruct.modelVar_PGAT_i)?0.0:1.0);
d_pbot2_dX = 0.0;
pbot2 = (0.9*std::min(modelStruct.modelVar_PSTI_i,modelStruct.modelVar_PGAT_i));
}
d_vbibot2r_dX = (modelStruct.d_modelVar_VBIRSTI_i_dX+modelStruct.d_modelVar_VBIRGAT_i_dX);
vbibot2r = (modelStruct.modelVar_VBIRSTI_i+modelStruct.modelVar_VBIRGAT_i);
}
if ((instanceStruct.instanceVar_LS_i==0.0))
{
d_vbisti2_dX = (modelStruct.d_modelVar_vbibot_dX+modelStruct.d_modelVar_vbigat_dX);
vbisti2 = (modelStruct.modelVar_vbibot+modelStruct.modelVar_vbigat);
{
double value_min_0 = std::min(modelStruct.modelVar_PBOT_i,modelStruct.modelVar_PGAT_i);
double  deriv_min_0_d0 = ((modelStruct.modelVar_PBOT_i<=modelStruct.modelVar_PGAT_i)?1.0:0.0);
double  deriv_min_0_d1 = ((modelStruct.modelVar_PBOT_i<=modelStruct.modelVar_PGAT_i)?0.0:1.0);
d_psti2_dX = 0.0;
psti2 = (0.9*std::min(modelStruct.modelVar_PBOT_i,modelStruct.modelVar_PGAT_i));
}
d_vbisti2r_dX = (modelStruct.d_modelVar_VBIRBOT_i_dX+modelStruct.d_modelVar_VBIRGAT_i_dX);
vbisti2r = (modelStruct.modelVar_VBIRBOT_i+modelStruct.modelVar_VBIRGAT_i);
}
if ((instanceStruct.instanceVar_LG_i==0.0))
{
d_vbigat2_dX = (modelStruct.d_modelVar_vbibot_dX+modelStruct.d_modelVar_vbisti_dX);
vbigat2 = (modelStruct.modelVar_vbibot+modelStruct.modelVar_vbisti);
{
double value_min_0 = std::min(modelStruct.modelVar_PBOT_i,modelStruct.modelVar_PSTI_i);
double  deriv_min_0_d0 = ((modelStruct.modelVar_PBOT_i<=modelStruct.modelVar_PSTI_i)?1.0:0.0);
double  deriv_min_0_d1 = ((modelStruct.modelVar_PBOT_i<=modelStruct.modelVar_PSTI_i)?0.0:1.0);
d_pgat2_dX = 0.0;
pgat2 = (0.9*std::min(modelStruct.modelVar_PBOT_i,modelStruct.modelVar_PSTI_i));
}
d_vbigat2r_dX = (modelStruct.d_modelVar_VBIRBOT_i_dX+modelStruct.d_modelVar_VBIRSTI_i_dX);
vbigat2r = (modelStruct.modelVar_VBIRBOT_i+modelStruct.modelVar_VBIRSTI_i);
}
{
double value_min_0 = std::min(vbibot2,vbisti2);
double value_min_1 = std::min(std::min(vbibot2,vbisti2),vbigat2);
double  deriv_min_0_d0 = ((vbibot2<=vbisti2)?1.0:0.0);
double  deriv_min_0_d1 = ((vbibot2<=vbisti2)?0.0:1.0);
double  deriv_min_1_d0 = ((std::min(vbibot2,vbisti2)<=vbigat2)?1.0:0.0);
double  deriv_min_1_d1 = ((std::min(vbibot2,vbisti2)<=vbigat2)?0.0:1.0);
instanceStruct.d_instanceVar_vbimin_dX = 0.0;
instanceStruct.instanceVar_vbimin = std::min(std::min(vbibot2,vbisti2),vbigat2);
}
instanceStruct.d_instanceVar_vch_dX = instanceStruct.d_instanceVar_vbimin_dX*0.1;
instanceStruct.instanceVar_vch = (instanceStruct.instanceVar_vbimin*0.1);
{
double value_max_0 = std::max(pbot2,psti2);
double value_max_1 = std::max(value_max_0,pgat2);
double  deriv_max_0_d0 = ((pbot2>=psti2)?1.0:0.0);
double  deriv_max_0_d1 = ((pbot2>=psti2)?0.0:1.0);
double  deriv_max_1_d0 = ((value_max_0>=pgat2)?1.0:0.0);
double  deriv_max_1_d1 = ((value_max_0>=pgat2)?0.0:1.0);
d_pmax_dX = ((deriv_max_1_d0*(((deriv_max_0_d0*(d_pbot2_dX))+(deriv_max_0_d1*(d_psti2_dX)))))+(deriv_max_1_d1*(d_pgat2_dX)));
pmax = value_max_1;
}
{
double value_pow_0 = pow(2.0,((-1.0)/pmax));
double  deriv_pow_0_d1 = (2.0 == 0.0)?0.0:(log(2.0)*value_pow_0);
instanceStruct.d_instanceVar_vfmin_dX = (instanceStruct.instanceVar_vbimin*(-(deriv_pow_0_d1*((-(-1.0)*d_pmax_dX/pmax/pmax))))+instanceStruct.d_instanceVar_vbimin_dX*(1.0-value_pow_0));
instanceStruct.instanceVar_vfmin = (instanceStruct.instanceVar_vbimin*(1.0-value_pow_0));
}
{
double value_min_0 = std::min(vbibot2r,vbisti2r);
double value_min_1 = std::min(std::min(vbibot2r,vbisti2r),vbigat2r);
double  deriv_min_0_d0 = ((vbibot2r<=vbisti2r)?1.0:0.0);
double  deriv_min_0_d1 = ((vbibot2r<=vbisti2r)?0.0:1.0);
double  deriv_min_1_d0 = ((std::min(vbibot2r,vbisti2r)<=vbigat2r)?1.0:0.0);
double  deriv_min_1_d1 = ((std::min(vbibot2r,vbisti2r)<=vbigat2r)?0.0:1.0);
instanceStruct.d_instanceVar_vbbtlim_dX = 0.0;
instanceStruct.instanceVar_vbbtlim = (std::min(std::min(vbibot2r,vbisti2r),vbigat2r)-5.0e-2);
}
instanceStruct.d_instanceVar_ISATFOR1_dX = 0.0;
instanceStruct.instanceVar_ISATFOR1 = 0.0;
instanceStruct.instanceVar_MFOR1 = 1.0;
instanceStruct.d_instanceVar_MFOR2_dX = 0.0;
instanceStruct.instanceVar_MFOR2 = 1.0;
instanceStruct.d_instanceVar_ISATFOR2_dX = 0.0;
instanceStruct.instanceVar_ISATFOR2 = 0.0;
instanceStruct.d_instanceVar_MREV_dX = 0.0;
instanceStruct.instanceVar_MREV = 1.0;
instanceStruct.d_instanceVar_ISATREV_dX = 0.0;
instanceStruct.instanceVar_ISATREV = 0.0;
instanceStruct.instanceVar_m0flag = 0.0;
instanceStruct.d_instanceVar_xhighf1_dX = 0.0;
instanceStruct.instanceVar_xhighf1 = 0.0;
instanceStruct.d_instanceVar_expxhf1_dX = 0.0;
instanceStruct.instanceVar_expxhf1 = 0.0;
instanceStruct.d_instanceVar_xhighf2_dX = 0.0;
instanceStruct.instanceVar_xhighf2 = 0.0;
instanceStruct.d_instanceVar_expxhf2_dX = 0.0;
instanceStruct.instanceVar_expxhf2 = 0.0;
instanceStruct.d_instanceVar_xhighr_dX = 0.0;
instanceStruct.instanceVar_xhighr = 0.0;
instanceStruct.d_instanceVar_expxhr_dX = 0.0;
instanceStruct.instanceVar_expxhr = 0.0;
d_m0_rev_dX = 0.0;
m0_rev = 0.0;
d_mcor_rev_dX = 0.0;
mcor_rev = 0.0;
d_I1_cor_dX = 0.0;
I1_cor = 0.0;
d_I2_cor_dX = 0.0;
I2_cor = 0.0;
d_I3_cor_dX = 0.0;
I3_cor = 0.0;
d_I4_cor_dX = 0.0;
I4_cor = 0.0;
d_I5_cor_dX = 0.0;
I5_cor = 0.0;
d_tt0_dX = 0.0;
tt0 = 0.0;
d_tt1_dX = 0.0;
tt1 = 0.0;
d_tt2_dX = 0.0;
tt2 = 0.0;
d_zfrac_dX = 0.0;
zfrac = 0.0;
instanceStruct.instanceVar_zflagbot = 1.0;
instanceStruct.instanceVar_zflagsti = 1.0;
instanceStruct.instanceVar_zflaggat = 1.0;
d_alphaje_dX = 0.0;
alphaje = 0.0;
if ((modelStruct.modelVar_SWJUNEXP_i==1.0))
//Begin block JUNCAPexpressInit
{
//Block-local variables for block JUNCAPexpressInit
double ysq=0.0;
double d_ysq_dX=0.0;
double terfc=0.0;
double d_terfc_dX=0.0;
double erfcpos=0.0;
double d_erfcpos_dX=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double h1=0.0;
double d_h1_dX=0.0;
double h2=0.0;
double d_h2_dX=0.0;
double h2d=0.0;
double d_h2d_dX=0.0;
double h3=0.0;
double d_h3_dX=0.0;
double h4=0.0;
double d_h4_dX=0.0;
double h5=0.0;
double d_h5_dX=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double idmult=0.0;
double d_idmult_dX=0.0;
double vj=0.0;
double d_vj_dX=0.0;
double z=0.0;
double d_z_dX=0.0;
double zinv=0.0;
double d_zinv_dX=0.0;
double two_psistar=0.0;
double d_two_psistar_dX=0.0;
double vjlim=0.0;
double d_vjlim_dX=0.0;
double vjsrh=0.0;
double d_vjsrh_dX=0.0;
double vbbt=0.0;
double d_vbbt_dX=0.0;
double vav=0.0;
double d_vav_dX=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double tmp=0.0;
double d_tmp_dX=0.0;
double id=0.0;
double d_id_dX=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double isrh=0.0;
double d_isrh_dX=0.0;
double vbi_minus_vjsrh=0.0;
double d_vbi_minus_vjsrh_dX=0.0;
double wsrhstep=0.0;
double d_wsrhstep_dX=0.0;
double dwsrh=0.0;
double d_dwsrh_dX=0.0;
double wsrh=0.0;
double d_wsrh_dX=0.0;
double wdep=0.0;
double d_wdep_dX=0.0;
double asrh=0.0;
double d_asrh_dX=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double itat=0.0;
double d_itat_dX=0.0;
double btat=0.0;
double d_btat_dX=0.0;
double twoatatoverthreebtat=0.0;
double d_twoatatoverthreebtat_dX=0.0;
double umaxbeforelimiting=0.0;
double d_umaxbeforelimiting_dX=0.0;
double umax=0.0;
double d_umax_dX=0.0;
double sqrtumax=0.0;
double d_sqrtumax_dX=0.0;
double umaxpoweronepointfive=0.0;
double d_umaxpoweronepointfive_dX=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double wgamma=0.0;
double d_wgamma_dX=0.0;
double wtat=0.0;
double d_wtat_dX=0.0;
double ktat=0.0;
double d_ktat_dX=0.0;
double ltat=0.0;
double d_ltat_dX=0.0;
double mtat=0.0;
double d_mtat_dX=0.0;
double xerfc=0.0;
double d_xerfc_dX=0.0;
double erfctimesexpmtat=0.0;
double d_erfctimesexpmtat_dX=0.0;
double gammamax=0.0;
double d_gammamax_dX=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double ibbt=0.0;
double d_ibbt_dX=0.0;
double Fmaxr=0.0;
double d_Fmaxr_dX=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double fbreakdown=0.0;
double d_fbreakdown_dX=0.0;
//End of Block-local variables
//Block-local variables for block JUNCAPexpressInit
double ijunbot=0.0;
double d_ijunbot_dX=0.0;
double ijunsti=0.0;
double d_ijunsti_dX=0.0;
double ijungat=0.0;
double d_ijungat_dX=0.0;
double qjunbot=0.0;
double d_qjunbot_dX=0.0;
double qjunsti=0.0;
double d_qjunsti_dX=0.0;
double qjungat=0.0;
double d_qjungat_dX=0.0;
//End of Block-local variables
d_ysq_dX = 0.0;
ysq = 0.0;
d_terfc_dX = 0.0;
terfc = 0.0;
d_erfcpos_dX = 0.0;
erfcpos = 0.0;
d_h1_dX = 0.0;
h1 = 0.0;
d_h2_dX = 0.0;
h2 = 0.0;
d_h2d_dX = 0.0;
h2d = 0.0;
d_h3_dX = 0.0;
h3 = 0.0;
d_h4_dX = 0.0;
h4 = 0.0;
d_h5_dX = 0.0;
h5 = 0.0;
d_idmult_dX = 0.0;
idmult = 0.0;
d_vj_dX = 0.0;
vj = 0.0;
d_z_dX = 0.0;
z = 0.0;
d_zinv_dX = 0.0;
zinv = 0.0;
d_two_psistar_dX = 0.0;
two_psistar = 0.0;
d_vjlim_dX = 0.0;
vjlim = 0.0;
d_vjsrh_dX = 0.0;
vjsrh = 0.0;
d_vbbt_dX = 0.0;
vbbt = 0.0;
d_vav_dX = 0.0;
vav = 0.0;
d_tmp_dX = 0.0;
tmp = 0.0;
d_id_dX = 0.0;
id = 0.0;
d_isrh_dX = 0.0;
isrh = 0.0;
d_vbi_minus_vjsrh_dX = 0.0;
vbi_minus_vjsrh = 0.0;
d_wsrhstep_dX = 0.0;
wsrhstep = 0.0;
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
d_wsrh_dX = 0.0;
wsrh = 0.0;
d_wdep_dX = 0.0;
wdep = 0.0;
d_asrh_dX = 0.0;
asrh = 0.0;
d_itat_dX = 0.0;
itat = 0.0;
d_btat_dX = 0.0;
btat = 0.0;
d_twoatatoverthreebtat_dX = 0.0;
twoatatoverthreebtat = 0.0;
d_umaxbeforelimiting_dX = 0.0;
umaxbeforelimiting = 0.0;
d_umax_dX = 0.0;
umax = 0.0;
d_sqrtumax_dX = 0.0;
sqrtumax = 0.0;
d_umaxpoweronepointfive_dX = 0.0;
umaxpoweronepointfive = 0.0;
d_wgamma_dX = 0.0;
wgamma = 0.0;
d_wtat_dX = 0.0;
wtat = 0.0;
d_ktat_dX = 0.0;
ktat = 0.0;
d_ltat_dX = 0.0;
ltat = 0.0;
d_mtat_dX = 0.0;
mtat = 0.0;
d_xerfc_dX = 0.0;
xerfc = 0.0;
d_erfctimesexpmtat_dX = 0.0;
erfctimesexpmtat = 0.0;
d_gammamax_dX = 0.0;
gammamax = 0.0;
d_ibbt_dX = 0.0;
ibbt = 0.0;
d_Fmaxr_dX = 0.0;
Fmaxr = 0.0;
d_fbreakdown_dX = 0.0;
fbreakdown = 0.0;
d_qjunbot_dX = 0.0;
qjunbot = 0.0;
d_qjunsti_dX = 0.0;
qjunsti = 0.0;
d_qjungat_dX = 0.0;
qjungat = 0.0;
FRACNA = 0.4;
FRACNB = 0.65;
FRACI = 0.8;
d_V1_dX = (-FRACNA)*modelStruct.d_modelVar_VJUNREF_i_dX;
V1 = ((-FRACNA)*modelStruct.modelVar_VJUNREF_i);
d_V2_dX = (-FRACNB)*modelStruct.d_modelVar_VJUNREF_i_dX;
V2 = ((-FRACNB)*modelStruct.modelVar_VJUNREF_i);
d_V3_dX = (-FRACI)*modelStruct.d_modelVar_VJUNREF_i_dX;
V3 = ((-FRACI)*modelStruct.modelVar_VJUNREF_i);
V4 = 0.1;
V5 = 0.2;
d_vbbt_dX = 0.0;
vbbt = 0.0;
d_two_psistar_dX = 0.0;
two_psistar = 0.0;
if ((!(((instanceStruct.instanceVar_AB_i==0.0)&&(instanceStruct.instanceVar_LS_i==0.0))&&(instanceStruct.instanceVar_LG_i==0.0))))
{
d_h1_dX = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.d_instanceVar_vch_dX+4.0*instanceStruct.d_instanceVar_vch_dX*instanceStruct.instanceVar_vch);
h1 = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.instanceVar_vch);
d_h2_dX = ((instanceStruct.instanceVar_vfmin*instanceStruct.d_instanceVar_vch_dX-instanceStruct.instanceVar_vch*instanceStruct.d_instanceVar_vfmin_dX)/instanceStruct.instanceVar_vfmin/instanceStruct.instanceVar_vfmin);
h2 = (instanceStruct.instanceVar_vch/instanceStruct.instanceVar_vfmin);
d_h2d_dX = (d_V1_dX+(instanceStruct.instanceVar_vch*d_h2_dX+instanceStruct.d_instanceVar_vch_dX*h2));
h2d = (V1+(instanceStruct.instanceVar_vch*h2));
d_h3_dX = (instanceStruct.d_instanceVar_vfmin_dX+d_h2d_dX);
h3 = (instanceStruct.instanceVar_vfmin+h2d);
d_h4_dX = (instanceStruct.d_instanceVar_vfmin_dX-d_h2d_dX);
h4 = (instanceStruct.instanceVar_vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_h5_dX = deriv_sqrt_0_d0*(((h4*d_h4_dX+d_h4_dX*h4)+d_h1_dX));
h5 = value_sqrt_0;
}
d_vj_dX = 2.0*(((h3+h5)*(V1*instanceStruct.d_instanceVar_vfmin_dX+d_V1_dX*instanceStruct.instanceVar_vfmin)-(V1*instanceStruct.instanceVar_vfmin)*(d_h3_dX+d_h5_dX))/(h3+h5)/(h3+h5));
vj = (2.0*((V1*instanceStruct.instanceVar_vfmin)/(h3+h5)));
if ((V1<instanceStruct.instanceVar_VMAX))
{
if ((fabs((0.5*(V1*modelStruct.modelVar_phitdinv)))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(V1*modelStruct.modelVar_phitdinv)));
double  deriv_exp_0_d0 = value_exp_0;
d_zinv_dX = deriv_exp_0_d0*(0.5*(V1*modelStruct.d_modelVar_phitdinv_dX+d_V1_dX*modelStruct.modelVar_phitdinv));
zinv = value_exp_0;
}
}
else
{
if (((0.5*(V1*modelStruct.modelVar_phitdinv))<0.0))
{
d_zinv_dX = (-1.0e-100*(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*0.5*(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*(-0.5*(V1*modelStruct.d_modelVar_phitdinv_dX+d_V1_dX*modelStruct.modelVar_phitdinv))*3.3333333333333333e-01+(-0.5*(V1*modelStruct.d_modelVar_phitdinv_dX+d_V1_dX*modelStruct.modelVar_phitdinv))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))+(-0.5*(V1*modelStruct.d_modelVar_phitdinv_dX+d_V1_dX*modelStruct.modelVar_phitdinv))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V1*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
}
else
{
d_zinv_dX = 1.0e100*(((0.5*(V1*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*(((0.5*(V1*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*(V1*modelStruct.d_modelVar_phitdinv_dX+d_V1_dX*modelStruct.modelVar_phitdinv)*3.3333333333333333e-01+0.5*(V1*modelStruct.d_modelVar_phitdinv_dX+d_V1_dX*modelStruct.modelVar_phitdinv)*(1.0+(((0.5*(V1*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01)))+0.5*(V1*modelStruct.d_modelVar_phitdinv_dX+d_V1_dX*modelStruct.modelVar_phitdinv)*(1.0+(0.5*(((0.5*(V1*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(V1*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))));
zinv = (1.0e100*(1.0+(((0.5*(V1*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(V1*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(V1*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_idmult_dX = (zinv*d_zinv_dX+d_zinv_dX*zinv);
idmult = (zinv*zinv);
}
else
{
d_idmult_dX = ((1.0+((V1-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX+((V1-instanceStruct.instanceVar_VMAX)*modelStruct.d_modelVar_phitdinv_dX+(d_V1_dX-instanceStruct.d_instanceVar_VMAX_dX)*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_exp_VMAX_over_phitd);
idmult = ((1.0+((V1-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.instanceVar_exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_zinv_dX = deriv_sqrt_0_d0*(d_idmult_dX);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
d_z_dX = (-d_zinv_dX/zinv/zinv);
z = (1.0/zinv);
if ((V1>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/((2.0+z)+value_sqrt_0));
d_two_psistar_dX = 2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((d_z_dX+deriv_sqrt_0_d0*(((z+1.0)*d_z_dX+d_z_dX*(z+3.0)))))+modelStruct.d_modelVar_phitd_dX*value_log_1);
two_psistar = (2.0*(modelStruct.modelVar_phitd*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/(((2.0*zinv)+1.0)+value_sqrt_0));
d_two_psistar_dX = ((-d_V1_dX)+2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((2.0*d_zinv_dX+deriv_sqrt_0_d0*(((1.0+zinv)*3.0*d_zinv_dX+d_zinv_dX*(1.0+(3.0*zinv))))))+modelStruct.d_modelVar_phitd_dX*value_log_1));
two_psistar = ((-V1)+(2.0*(modelStruct.modelVar_phitd*value_log_1)));
}
}
d_vjlim_dX = (instanceStruct.d_instanceVar_vbimin_dX-d_two_psistar_dX);
vjlim = (instanceStruct.instanceVar_vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((V1-vjlim)*(V1-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.modelVar_phitd)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vjsrh_dX = 0.5*((d_V1_dX+d_vjlim_dX)-deriv_sqrt_0_d0*((((V1-vjlim)*(d_V1_dX-d_vjlim_dX)+(d_V1_dX-d_vjlim_dX)*(V1-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.d_modelVar_phitd_dX+4.0*modelStruct.d_modelVar_phitd_dX*modelStruct.modelVar_phitd))));
vjsrh = (0.5*((V1+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V1-instanceStruct.instanceVar_vbbtlim)*(V1-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.modelVar_phitr)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vbbt_dX = 0.5*((d_V1_dX+instanceStruct.d_instanceVar_vbbtlim_dX)-deriv_sqrt_0_d0*((((V1-instanceStruct.instanceVar_vbbtlim)*(d_V1_dX-instanceStruct.d_instanceVar_vbbtlim_dX)+(d_V1_dX-instanceStruct.d_instanceVar_vbbtlim_dX)*(V1-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.d_modelVar_phitr_dX+4.0*modelStruct.d_modelVar_phitr_dX*modelStruct.modelVar_phitr))));
vbbt = (0.5*((V1+instanceStruct.instanceVar_vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V1)*(V1))+((4.0*1.0e-6)*1.0e-6)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vav_dX = 0.5*(d_V1_dX-deriv_sqrt_0_d0*(((V1)*d_V1_dX+d_V1_dX*(V1))));
vav = (0.5*(V1-value_sqrt_0));
}
}
if ((instanceStruct.instanceVar_AB_i==0.0))
{
d_ijunbot_dX = 0.0;
ijunbot = 0.0;
d_qjunbot_dX = 0.0;
qjunbot = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PBOT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvbot)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvbot)),modelStruct.modelVar_one_minus_PBOT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PBOT/(1.0-(vj*modelStruct.modelVar_vbiinvbot))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvbot)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PBOT_dX)));
tmp = value_pow_0;
}
}
d_qjunbot_dX = ((modelStruct.modelVar_qprefbot*(-d_tmp_dX)+modelStruct.d_modelVar_qprefbot_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(d_V1_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2bot_dX*(V1-vj)));
qjunbot = ((modelStruct.modelVar_qprefbot*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(V1-vj)));
d_id_dX = (modelStruct.modelVar_idsatbot*d_idmult_dX+modelStruct.d_modelVar_idsatbot_dX*idmult);
id = (modelStruct.modelVar_idsatbot*idmult);
if (((modelStruct.modelVar_CSRHBOT_i==0.0)&&(modelStruct.modelVar_CTATBOT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbibot_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbibot-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PBOT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PBOT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrbot*d_tmp_dX+modelStruct.d_modelVar_wdepnulrbot_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrbot*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdbot*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdbot_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdbot*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHBOT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHBOT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHBOT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATBOT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartbot*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PBOT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PBOT)-(wdep*modelStruct.modelVar_one_minus_PBOT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartbot_dX*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartbot*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatbot_dX-(0.666666666666667*modelStruct.modelVar_atatbot)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatbot)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PBOT_i)*modelStruct.d_modelVar_one_over_one_minus_PBOT_dX+(-modelStruct.d_modelVar_PBOT_i_dX)*modelStruct.modelVar_one_over_one_minus_PBOT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatbot*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatbot_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*d_umax_dX+modelStruct.d_modelVar_atatbot_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatbot*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatbot_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatbot*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatbot*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATBOT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTBOT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PBOT*((tmp*((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvbot_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvbot)-((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PBOT_dX*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PBOT*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtbot)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtbot)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtbot)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTBOT_i*(((V1*Fmaxr)*Fmaxr)*d_tmp_dX+((V1*Fmaxr)*d_Fmaxr_dX+(V1*d_Fmaxr_dX+d_V1_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTBOT_i_dX*(((V1*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTBOT_i*(((V1*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRBOT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRBOT_i)))
{
if ((modelStruct.modelVar_PBRBOT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
tmp = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvbot));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRBOT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvbot))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRBOT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRBOT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopbot_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.d_modelVar_slopebot_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRBOT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
fbreakdown = (modelStruct.modelVar_fstopbot+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
}
}
d_ijunbot_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LS_i==0.0))
{
d_ijunsti_dX = 0.0;
ijunsti = 0.0;
d_qjunsti_dX = 0.0;
qjunsti = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PSTI==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvsti)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvsti)),modelStruct.modelVar_one_minus_PSTI);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PSTI/(1.0-(vj*modelStruct.modelVar_vbiinvsti))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvsti)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PSTI_dX)));
tmp = value_pow_0;
}
}
d_qjunsti_dX = ((modelStruct.modelVar_qprefsti*(-d_tmp_dX)+modelStruct.d_modelVar_qprefsti_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(d_V1_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2sti_dX*(V1-vj)));
qjunsti = ((modelStruct.modelVar_qprefsti*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(V1-vj)));
d_id_dX = (modelStruct.modelVar_idsatsti*d_idmult_dX+modelStruct.d_modelVar_idsatsti_dX*idmult);
id = (modelStruct.modelVar_idsatsti*idmult);
if (((modelStruct.modelVar_CSRHSTI_i==0.0)&&(modelStruct.modelVar_CTATSTI_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbisti_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbisti-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PSTI_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PSTI_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrsti*d_tmp_dX+modelStruct.d_modelVar_wdepnulrsti_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrsti*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdsti*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdsti_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdsti*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHSTI_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHSTI_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHSTI_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATSTI_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartsti*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PSTI_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PSTI)-(wdep*modelStruct.modelVar_one_minus_PSTI)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartsti_dX*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartsti*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatsti_dX-(0.666666666666667*modelStruct.modelVar_atatsti)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatsti)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PSTI_i)*modelStruct.d_modelVar_one_over_one_minus_PSTI_dX+(-modelStruct.d_modelVar_PSTI_i_dX)*modelStruct.modelVar_one_over_one_minus_PSTI))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatsti*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatsti_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*d_umax_dX+modelStruct.d_modelVar_atatsti_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatsti*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatsti_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatsti*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatsti*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATSTI_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTSTI_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PSTI*((tmp*((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvsti_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvsti)-((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PSTI_dX*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PSTI*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtsti)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtsti)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtsti)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTSTI_i*(((V1*Fmaxr)*Fmaxr)*d_tmp_dX+((V1*Fmaxr)*d_Fmaxr_dX+(V1*d_Fmaxr_dX+d_V1_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTSTI_i_dX*(((V1*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTSTI_i*(((V1*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRSTI_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRSTI_i)))
{
if ((modelStruct.modelVar_PBRSTI_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
tmp = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvsti));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRSTI_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvsti))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRSTI_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRSTI_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopsti_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.d_modelVar_slopesti_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRSTI_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
fbreakdown = (modelStruct.modelVar_fstopsti+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
}
}
d_ijunsti_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LG_i==0.0))
{
d_ijungat_dX = 0.0;
ijungat = 0.0;
d_qjungat_dX = 0.0;
qjungat = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PGAT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvgat)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvgat)),modelStruct.modelVar_one_minus_PGAT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PGAT/(1.0-(vj*modelStruct.modelVar_vbiinvgat))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvgat)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PGAT_dX)));
tmp = value_pow_0;
}
}
d_qjungat_dX = ((modelStruct.modelVar_qprefgat*(-d_tmp_dX)+modelStruct.d_modelVar_qprefgat_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(d_V1_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2gat_dX*(V1-vj)));
qjungat = ((modelStruct.modelVar_qprefgat*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(V1-vj)));
d_id_dX = (modelStruct.modelVar_idsatgat*d_idmult_dX+modelStruct.d_modelVar_idsatgat_dX*idmult);
id = (modelStruct.modelVar_idsatgat*idmult);
if (((modelStruct.modelVar_CSRHGAT_i==0.0)&&(modelStruct.modelVar_CTATGAT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbigat_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbigat-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PGAT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PGAT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrgat*d_tmp_dX+modelStruct.d_modelVar_wdepnulrgat_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrgat*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdgat*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdgat_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdgat*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHGAT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHGAT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHGAT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATGAT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartgat*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PGAT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PGAT)-(wdep*modelStruct.modelVar_one_minus_PGAT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartgat_dX*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartgat*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatgat_dX-(0.666666666666667*modelStruct.modelVar_atatgat)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatgat)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PGAT_i)*modelStruct.d_modelVar_one_over_one_minus_PGAT_dX+(-modelStruct.d_modelVar_PGAT_i_dX)*modelStruct.modelVar_one_over_one_minus_PGAT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatgat*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatgat_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*d_umax_dX+modelStruct.d_modelVar_atatgat_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatgat*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatgat_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatgat*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatgat*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATGAT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTGAT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PGAT*((tmp*((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvgat_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvgat)-((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PGAT_dX*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PGAT*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtgat)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtgat)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtgat)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTGAT_i*(((V1*Fmaxr)*Fmaxr)*d_tmp_dX+((V1*Fmaxr)*d_Fmaxr_dX+(V1*d_Fmaxr_dX+d_V1_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTGAT_i_dX*(((V1*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTGAT_i*(((V1*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRGAT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRGAT_i)))
{
if ((modelStruct.modelVar_PBRGAT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
tmp = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvgat));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRGAT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvgat))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRGAT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRGAT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopgat_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.d_modelVar_slopegat_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRGAT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
fbreakdown = (modelStruct.modelVar_fstopgat+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
}
}
d_ijungat_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
d_I1_dX = (((instanceStruct.instanceVar_AB_i*d_ijunbot_dX+instanceStruct.d_instanceVar_AB_i_dX*ijunbot)+(instanceStruct.instanceVar_LS_i*d_ijunsti_dX+instanceStruct.d_instanceVar_LS_i_dX*ijunsti))+(instanceStruct.instanceVar_LG_i*d_ijungat_dX+instanceStruct.d_instanceVar_LG_i_dX*ijungat));
I1 = (((instanceStruct.instanceVar_AB_i*ijunbot)+(instanceStruct.instanceVar_LS_i*ijunsti))+(instanceStruct.instanceVar_LG_i*ijungat));
d_vbbt_dX = 0.0;
vbbt = 0.0;
d_two_psistar_dX = 0.0;
two_psistar = 0.0;
if ((!(((instanceStruct.instanceVar_AB_i==0.0)&&(instanceStruct.instanceVar_LS_i==0.0))&&(instanceStruct.instanceVar_LG_i==0.0))))
{
d_h1_dX = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.d_instanceVar_vch_dX+4.0*instanceStruct.d_instanceVar_vch_dX*instanceStruct.instanceVar_vch);
h1 = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.instanceVar_vch);
d_h2_dX = ((instanceStruct.instanceVar_vfmin*instanceStruct.d_instanceVar_vch_dX-instanceStruct.instanceVar_vch*instanceStruct.d_instanceVar_vfmin_dX)/instanceStruct.instanceVar_vfmin/instanceStruct.instanceVar_vfmin);
h2 = (instanceStruct.instanceVar_vch/instanceStruct.instanceVar_vfmin);
d_h2d_dX = (d_V2_dX+(instanceStruct.instanceVar_vch*d_h2_dX+instanceStruct.d_instanceVar_vch_dX*h2));
h2d = (V2+(instanceStruct.instanceVar_vch*h2));
d_h3_dX = (instanceStruct.d_instanceVar_vfmin_dX+d_h2d_dX);
h3 = (instanceStruct.instanceVar_vfmin+h2d);
d_h4_dX = (instanceStruct.d_instanceVar_vfmin_dX-d_h2d_dX);
h4 = (instanceStruct.instanceVar_vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_h5_dX = deriv_sqrt_0_d0*(((h4*d_h4_dX+d_h4_dX*h4)+d_h1_dX));
h5 = value_sqrt_0;
}
d_vj_dX = 2.0*(((h3+h5)*(V2*instanceStruct.d_instanceVar_vfmin_dX+d_V2_dX*instanceStruct.instanceVar_vfmin)-(V2*instanceStruct.instanceVar_vfmin)*(d_h3_dX+d_h5_dX))/(h3+h5)/(h3+h5));
vj = (2.0*((V2*instanceStruct.instanceVar_vfmin)/(h3+h5)));
if ((V2<instanceStruct.instanceVar_VMAX))
{
if ((fabs((0.5*(V2*modelStruct.modelVar_phitdinv)))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(V2*modelStruct.modelVar_phitdinv)));
double  deriv_exp_0_d0 = value_exp_0;
d_zinv_dX = deriv_exp_0_d0*(0.5*(V2*modelStruct.d_modelVar_phitdinv_dX+d_V2_dX*modelStruct.modelVar_phitdinv));
zinv = value_exp_0;
}
}
else
{
if (((0.5*(V2*modelStruct.modelVar_phitdinv))<0.0))
{
d_zinv_dX = (-1.0e-100*(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*0.5*(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*(-0.5*(V2*modelStruct.d_modelVar_phitdinv_dX+d_V2_dX*modelStruct.modelVar_phitdinv))*3.3333333333333333e-01+(-0.5*(V2*modelStruct.d_modelVar_phitdinv_dX+d_V2_dX*modelStruct.modelVar_phitdinv))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))+(-0.5*(V2*modelStruct.d_modelVar_phitdinv_dX+d_V2_dX*modelStruct.modelVar_phitdinv))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V2*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
}
else
{
d_zinv_dX = 1.0e100*(((0.5*(V2*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*(((0.5*(V2*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*(V2*modelStruct.d_modelVar_phitdinv_dX+d_V2_dX*modelStruct.modelVar_phitdinv)*3.3333333333333333e-01+0.5*(V2*modelStruct.d_modelVar_phitdinv_dX+d_V2_dX*modelStruct.modelVar_phitdinv)*(1.0+(((0.5*(V2*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01)))+0.5*(V2*modelStruct.d_modelVar_phitdinv_dX+d_V2_dX*modelStruct.modelVar_phitdinv)*(1.0+(0.5*(((0.5*(V2*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(V2*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))));
zinv = (1.0e100*(1.0+(((0.5*(V2*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(V2*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(V2*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_idmult_dX = (zinv*d_zinv_dX+d_zinv_dX*zinv);
idmult = (zinv*zinv);
}
else
{
d_idmult_dX = ((1.0+((V2-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX+((V2-instanceStruct.instanceVar_VMAX)*modelStruct.d_modelVar_phitdinv_dX+(d_V2_dX-instanceStruct.d_instanceVar_VMAX_dX)*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_exp_VMAX_over_phitd);
idmult = ((1.0+((V2-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.instanceVar_exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_zinv_dX = deriv_sqrt_0_d0*(d_idmult_dX);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
d_z_dX = (-d_zinv_dX/zinv/zinv);
z = (1.0/zinv);
if ((V2>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/((2.0+z)+value_sqrt_0));
d_two_psistar_dX = 2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((d_z_dX+deriv_sqrt_0_d0*(((z+1.0)*d_z_dX+d_z_dX*(z+3.0)))))+modelStruct.d_modelVar_phitd_dX*value_log_1);
two_psistar = (2.0*(modelStruct.modelVar_phitd*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/(((2.0*zinv)+1.0)+value_sqrt_0));
d_two_psistar_dX = ((-d_V2_dX)+2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((2.0*d_zinv_dX+deriv_sqrt_0_d0*(((1.0+zinv)*3.0*d_zinv_dX+d_zinv_dX*(1.0+(3.0*zinv))))))+modelStruct.d_modelVar_phitd_dX*value_log_1));
two_psistar = ((-V2)+(2.0*(modelStruct.modelVar_phitd*value_log_1)));
}
}
d_vjlim_dX = (instanceStruct.d_instanceVar_vbimin_dX-d_two_psistar_dX);
vjlim = (instanceStruct.instanceVar_vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((V2-vjlim)*(V2-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.modelVar_phitd)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vjsrh_dX = 0.5*((d_V2_dX+d_vjlim_dX)-deriv_sqrt_0_d0*((((V2-vjlim)*(d_V2_dX-d_vjlim_dX)+(d_V2_dX-d_vjlim_dX)*(V2-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.d_modelVar_phitd_dX+4.0*modelStruct.d_modelVar_phitd_dX*modelStruct.modelVar_phitd))));
vjsrh = (0.5*((V2+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V2-instanceStruct.instanceVar_vbbtlim)*(V2-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.modelVar_phitr)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vbbt_dX = 0.5*((d_V2_dX+instanceStruct.d_instanceVar_vbbtlim_dX)-deriv_sqrt_0_d0*((((V2-instanceStruct.instanceVar_vbbtlim)*(d_V2_dX-instanceStruct.d_instanceVar_vbbtlim_dX)+(d_V2_dX-instanceStruct.d_instanceVar_vbbtlim_dX)*(V2-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.d_modelVar_phitr_dX+4.0*modelStruct.d_modelVar_phitr_dX*modelStruct.modelVar_phitr))));
vbbt = (0.5*((V2+instanceStruct.instanceVar_vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V2)*(V2))+((4.0*1.0e-6)*1.0e-6)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vav_dX = 0.5*(d_V2_dX-deriv_sqrt_0_d0*(((V2)*d_V2_dX+d_V2_dX*(V2))));
vav = (0.5*(V2-value_sqrt_0));
}
}
if ((instanceStruct.instanceVar_AB_i==0.0))
{
d_ijunbot_dX = 0.0;
ijunbot = 0.0;
d_qjunbot_dX = 0.0;
qjunbot = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PBOT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvbot)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvbot)),modelStruct.modelVar_one_minus_PBOT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PBOT/(1.0-(vj*modelStruct.modelVar_vbiinvbot))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvbot)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PBOT_dX)));
tmp = value_pow_0;
}
}
d_qjunbot_dX = ((modelStruct.modelVar_qprefbot*(-d_tmp_dX)+modelStruct.d_modelVar_qprefbot_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(d_V2_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2bot_dX*(V2-vj)));
qjunbot = ((modelStruct.modelVar_qprefbot*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(V2-vj)));
d_id_dX = (modelStruct.modelVar_idsatbot*d_idmult_dX+modelStruct.d_modelVar_idsatbot_dX*idmult);
id = (modelStruct.modelVar_idsatbot*idmult);
if (((modelStruct.modelVar_CSRHBOT_i==0.0)&&(modelStruct.modelVar_CTATBOT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbibot_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbibot-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PBOT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PBOT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrbot*d_tmp_dX+modelStruct.d_modelVar_wdepnulrbot_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrbot*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdbot*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdbot_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdbot*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHBOT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHBOT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHBOT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATBOT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartbot*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PBOT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PBOT)-(wdep*modelStruct.modelVar_one_minus_PBOT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartbot_dX*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartbot*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatbot_dX-(0.666666666666667*modelStruct.modelVar_atatbot)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatbot)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PBOT_i)*modelStruct.d_modelVar_one_over_one_minus_PBOT_dX+(-modelStruct.d_modelVar_PBOT_i_dX)*modelStruct.modelVar_one_over_one_minus_PBOT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatbot*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatbot_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*d_umax_dX+modelStruct.d_modelVar_atatbot_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatbot*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatbot_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatbot*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatbot*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATBOT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTBOT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PBOT*((tmp*((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvbot_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvbot)-((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PBOT_dX*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PBOT*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtbot)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtbot)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtbot)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTBOT_i*(((V2*Fmaxr)*Fmaxr)*d_tmp_dX+((V2*Fmaxr)*d_Fmaxr_dX+(V2*d_Fmaxr_dX+d_V2_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTBOT_i_dX*(((V2*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTBOT_i*(((V2*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRBOT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRBOT_i)))
{
if ((modelStruct.modelVar_PBRBOT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
tmp = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvbot));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRBOT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvbot))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRBOT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRBOT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopbot_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.d_modelVar_slopebot_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRBOT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
fbreakdown = (modelStruct.modelVar_fstopbot+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
}
}
d_ijunbot_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LS_i==0.0))
{
d_ijunsti_dX = 0.0;
ijunsti = 0.0;
d_qjunsti_dX = 0.0;
qjunsti = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PSTI==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvsti)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvsti)),modelStruct.modelVar_one_minus_PSTI);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PSTI/(1.0-(vj*modelStruct.modelVar_vbiinvsti))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvsti)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PSTI_dX)));
tmp = value_pow_0;
}
}
d_qjunsti_dX = ((modelStruct.modelVar_qprefsti*(-d_tmp_dX)+modelStruct.d_modelVar_qprefsti_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(d_V2_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2sti_dX*(V2-vj)));
qjunsti = ((modelStruct.modelVar_qprefsti*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(V2-vj)));
d_id_dX = (modelStruct.modelVar_idsatsti*d_idmult_dX+modelStruct.d_modelVar_idsatsti_dX*idmult);
id = (modelStruct.modelVar_idsatsti*idmult);
if (((modelStruct.modelVar_CSRHSTI_i==0.0)&&(modelStruct.modelVar_CTATSTI_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbisti_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbisti-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PSTI_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PSTI_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrsti*d_tmp_dX+modelStruct.d_modelVar_wdepnulrsti_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrsti*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdsti*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdsti_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdsti*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHSTI_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHSTI_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHSTI_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATSTI_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartsti*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PSTI_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PSTI)-(wdep*modelStruct.modelVar_one_minus_PSTI)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartsti_dX*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartsti*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatsti_dX-(0.666666666666667*modelStruct.modelVar_atatsti)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatsti)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PSTI_i)*modelStruct.d_modelVar_one_over_one_minus_PSTI_dX+(-modelStruct.d_modelVar_PSTI_i_dX)*modelStruct.modelVar_one_over_one_minus_PSTI))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatsti*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatsti_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*d_umax_dX+modelStruct.d_modelVar_atatsti_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatsti*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatsti_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatsti*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatsti*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATSTI_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTSTI_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PSTI*((tmp*((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvsti_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvsti)-((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PSTI_dX*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PSTI*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtsti)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtsti)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtsti)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTSTI_i*(((V2*Fmaxr)*Fmaxr)*d_tmp_dX+((V2*Fmaxr)*d_Fmaxr_dX+(V2*d_Fmaxr_dX+d_V2_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTSTI_i_dX*(((V2*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTSTI_i*(((V2*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRSTI_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRSTI_i)))
{
if ((modelStruct.modelVar_PBRSTI_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
tmp = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvsti));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRSTI_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvsti))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRSTI_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRSTI_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopsti_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.d_modelVar_slopesti_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRSTI_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
fbreakdown = (modelStruct.modelVar_fstopsti+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
}
}
d_ijunsti_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LG_i==0.0))
{
d_ijungat_dX = 0.0;
ijungat = 0.0;
d_qjungat_dX = 0.0;
qjungat = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PGAT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvgat)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvgat)),modelStruct.modelVar_one_minus_PGAT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PGAT/(1.0-(vj*modelStruct.modelVar_vbiinvgat))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvgat)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PGAT_dX)));
tmp = value_pow_0;
}
}
d_qjungat_dX = ((modelStruct.modelVar_qprefgat*(-d_tmp_dX)+modelStruct.d_modelVar_qprefgat_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(d_V2_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2gat_dX*(V2-vj)));
qjungat = ((modelStruct.modelVar_qprefgat*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(V2-vj)));
d_id_dX = (modelStruct.modelVar_idsatgat*d_idmult_dX+modelStruct.d_modelVar_idsatgat_dX*idmult);
id = (modelStruct.modelVar_idsatgat*idmult);
if (((modelStruct.modelVar_CSRHGAT_i==0.0)&&(modelStruct.modelVar_CTATGAT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbigat_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbigat-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PGAT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PGAT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrgat*d_tmp_dX+modelStruct.d_modelVar_wdepnulrgat_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrgat*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdgat*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdgat_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdgat*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHGAT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHGAT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHGAT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATGAT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartgat*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PGAT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PGAT)-(wdep*modelStruct.modelVar_one_minus_PGAT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartgat_dX*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartgat*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatgat_dX-(0.666666666666667*modelStruct.modelVar_atatgat)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatgat)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PGAT_i)*modelStruct.d_modelVar_one_over_one_minus_PGAT_dX+(-modelStruct.d_modelVar_PGAT_i_dX)*modelStruct.modelVar_one_over_one_minus_PGAT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatgat*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatgat_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*d_umax_dX+modelStruct.d_modelVar_atatgat_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatgat*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatgat_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatgat*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatgat*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATGAT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTGAT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PGAT*((tmp*((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvgat_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvgat)-((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PGAT_dX*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PGAT*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtgat)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtgat)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtgat)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTGAT_i*(((V2*Fmaxr)*Fmaxr)*d_tmp_dX+((V2*Fmaxr)*d_Fmaxr_dX+(V2*d_Fmaxr_dX+d_V2_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTGAT_i_dX*(((V2*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTGAT_i*(((V2*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRGAT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRGAT_i)))
{
if ((modelStruct.modelVar_PBRGAT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
tmp = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvgat));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRGAT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvgat))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRGAT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRGAT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopgat_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.d_modelVar_slopegat_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRGAT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
fbreakdown = (modelStruct.modelVar_fstopgat+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
}
}
d_ijungat_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
d_I2_dX = (((instanceStruct.instanceVar_AB_i*d_ijunbot_dX+instanceStruct.d_instanceVar_AB_i_dX*ijunbot)+(instanceStruct.instanceVar_LS_i*d_ijunsti_dX+instanceStruct.d_instanceVar_LS_i_dX*ijunsti))+(instanceStruct.instanceVar_LG_i*d_ijungat_dX+instanceStruct.d_instanceVar_LG_i_dX*ijungat));
I2 = (((instanceStruct.instanceVar_AB_i*ijunbot)+(instanceStruct.instanceVar_LS_i*ijunsti))+(instanceStruct.instanceVar_LG_i*ijungat));
d_vbbt_dX = 0.0;
vbbt = 0.0;
d_two_psistar_dX = 0.0;
two_psistar = 0.0;
if ((!(((instanceStruct.instanceVar_AB_i==0.0)&&(instanceStruct.instanceVar_LS_i==0.0))&&(instanceStruct.instanceVar_LG_i==0.0))))
{
d_h1_dX = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.d_instanceVar_vch_dX+4.0*instanceStruct.d_instanceVar_vch_dX*instanceStruct.instanceVar_vch);
h1 = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.instanceVar_vch);
d_h2_dX = ((instanceStruct.instanceVar_vfmin*instanceStruct.d_instanceVar_vch_dX-instanceStruct.instanceVar_vch*instanceStruct.d_instanceVar_vfmin_dX)/instanceStruct.instanceVar_vfmin/instanceStruct.instanceVar_vfmin);
h2 = (instanceStruct.instanceVar_vch/instanceStruct.instanceVar_vfmin);
d_h2d_dX = (d_V3_dX+(instanceStruct.instanceVar_vch*d_h2_dX+instanceStruct.d_instanceVar_vch_dX*h2));
h2d = (V3+(instanceStruct.instanceVar_vch*h2));
d_h3_dX = (instanceStruct.d_instanceVar_vfmin_dX+d_h2d_dX);
h3 = (instanceStruct.instanceVar_vfmin+h2d);
d_h4_dX = (instanceStruct.d_instanceVar_vfmin_dX-d_h2d_dX);
h4 = (instanceStruct.instanceVar_vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_h5_dX = deriv_sqrt_0_d0*(((h4*d_h4_dX+d_h4_dX*h4)+d_h1_dX));
h5 = value_sqrt_0;
}
d_vj_dX = 2.0*(((h3+h5)*(V3*instanceStruct.d_instanceVar_vfmin_dX+d_V3_dX*instanceStruct.instanceVar_vfmin)-(V3*instanceStruct.instanceVar_vfmin)*(d_h3_dX+d_h5_dX))/(h3+h5)/(h3+h5));
vj = (2.0*((V3*instanceStruct.instanceVar_vfmin)/(h3+h5)));
if ((V3<instanceStruct.instanceVar_VMAX))
{
if ((fabs((0.5*(V3*modelStruct.modelVar_phitdinv)))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(V3*modelStruct.modelVar_phitdinv)));
double  deriv_exp_0_d0 = value_exp_0;
d_zinv_dX = deriv_exp_0_d0*(0.5*(V3*modelStruct.d_modelVar_phitdinv_dX+d_V3_dX*modelStruct.modelVar_phitdinv));
zinv = value_exp_0;
}
}
else
{
if (((0.5*(V3*modelStruct.modelVar_phitdinv))<0.0))
{
d_zinv_dX = (-1.0e-100*(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*0.5*(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*(-0.5*(V3*modelStruct.d_modelVar_phitdinv_dX+d_V3_dX*modelStruct.modelVar_phitdinv))*3.3333333333333333e-01+(-0.5*(V3*modelStruct.d_modelVar_phitdinv_dX+d_V3_dX*modelStruct.modelVar_phitdinv))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))+(-0.5*(V3*modelStruct.d_modelVar_phitdinv_dX+d_V3_dX*modelStruct.modelVar_phitdinv))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V3*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
}
else
{
d_zinv_dX = 1.0e100*(((0.5*(V3*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*(((0.5*(V3*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*(V3*modelStruct.d_modelVar_phitdinv_dX+d_V3_dX*modelStruct.modelVar_phitdinv)*3.3333333333333333e-01+0.5*(V3*modelStruct.d_modelVar_phitdinv_dX+d_V3_dX*modelStruct.modelVar_phitdinv)*(1.0+(((0.5*(V3*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01)))+0.5*(V3*modelStruct.d_modelVar_phitdinv_dX+d_V3_dX*modelStruct.modelVar_phitdinv)*(1.0+(0.5*(((0.5*(V3*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(V3*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))));
zinv = (1.0e100*(1.0+(((0.5*(V3*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(V3*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(V3*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_idmult_dX = (zinv*d_zinv_dX+d_zinv_dX*zinv);
idmult = (zinv*zinv);
}
else
{
d_idmult_dX = ((1.0+((V3-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX+((V3-instanceStruct.instanceVar_VMAX)*modelStruct.d_modelVar_phitdinv_dX+(d_V3_dX-instanceStruct.d_instanceVar_VMAX_dX)*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_exp_VMAX_over_phitd);
idmult = ((1.0+((V3-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.instanceVar_exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_zinv_dX = deriv_sqrt_0_d0*(d_idmult_dX);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
d_z_dX = (-d_zinv_dX/zinv/zinv);
z = (1.0/zinv);
if ((V3>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/((2.0+z)+value_sqrt_0));
d_two_psistar_dX = 2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((d_z_dX+deriv_sqrt_0_d0*(((z+1.0)*d_z_dX+d_z_dX*(z+3.0)))))+modelStruct.d_modelVar_phitd_dX*value_log_1);
two_psistar = (2.0*(modelStruct.modelVar_phitd*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/(((2.0*zinv)+1.0)+value_sqrt_0));
d_two_psistar_dX = ((-d_V3_dX)+2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((2.0*d_zinv_dX+deriv_sqrt_0_d0*(((1.0+zinv)*3.0*d_zinv_dX+d_zinv_dX*(1.0+(3.0*zinv))))))+modelStruct.d_modelVar_phitd_dX*value_log_1));
two_psistar = ((-V3)+(2.0*(modelStruct.modelVar_phitd*value_log_1)));
}
}
d_vjlim_dX = (instanceStruct.d_instanceVar_vbimin_dX-d_two_psistar_dX);
vjlim = (instanceStruct.instanceVar_vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((V3-vjlim)*(V3-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.modelVar_phitd)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vjsrh_dX = 0.5*((d_V3_dX+d_vjlim_dX)-deriv_sqrt_0_d0*((((V3-vjlim)*(d_V3_dX-d_vjlim_dX)+(d_V3_dX-d_vjlim_dX)*(V3-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.d_modelVar_phitd_dX+4.0*modelStruct.d_modelVar_phitd_dX*modelStruct.modelVar_phitd))));
vjsrh = (0.5*((V3+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V3-instanceStruct.instanceVar_vbbtlim)*(V3-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.modelVar_phitr)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vbbt_dX = 0.5*((d_V3_dX+instanceStruct.d_instanceVar_vbbtlim_dX)-deriv_sqrt_0_d0*((((V3-instanceStruct.instanceVar_vbbtlim)*(d_V3_dX-instanceStruct.d_instanceVar_vbbtlim_dX)+(d_V3_dX-instanceStruct.d_instanceVar_vbbtlim_dX)*(V3-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.d_modelVar_phitr_dX+4.0*modelStruct.d_modelVar_phitr_dX*modelStruct.modelVar_phitr))));
vbbt = (0.5*((V3+instanceStruct.instanceVar_vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V3)*(V3))+((4.0*1.0e-6)*1.0e-6)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vav_dX = 0.5*(d_V3_dX-deriv_sqrt_0_d0*(((V3)*d_V3_dX+d_V3_dX*(V3))));
vav = (0.5*(V3-value_sqrt_0));
}
}
if ((instanceStruct.instanceVar_AB_i==0.0))
{
d_ijunbot_dX = 0.0;
ijunbot = 0.0;
d_qjunbot_dX = 0.0;
qjunbot = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PBOT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvbot)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvbot)),modelStruct.modelVar_one_minus_PBOT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PBOT/(1.0-(vj*modelStruct.modelVar_vbiinvbot))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvbot)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PBOT_dX)));
tmp = value_pow_0;
}
}
d_qjunbot_dX = ((modelStruct.modelVar_qprefbot*(-d_tmp_dX)+modelStruct.d_modelVar_qprefbot_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(d_V3_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2bot_dX*(V3-vj)));
qjunbot = ((modelStruct.modelVar_qprefbot*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(V3-vj)));
d_id_dX = (modelStruct.modelVar_idsatbot*d_idmult_dX+modelStruct.d_modelVar_idsatbot_dX*idmult);
id = (modelStruct.modelVar_idsatbot*idmult);
if (((modelStruct.modelVar_CSRHBOT_i==0.0)&&(modelStruct.modelVar_CTATBOT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbibot_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbibot-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PBOT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PBOT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrbot*d_tmp_dX+modelStruct.d_modelVar_wdepnulrbot_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrbot*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdbot*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdbot_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdbot*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHBOT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHBOT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHBOT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATBOT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartbot*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PBOT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PBOT)-(wdep*modelStruct.modelVar_one_minus_PBOT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartbot_dX*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartbot*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatbot_dX-(0.666666666666667*modelStruct.modelVar_atatbot)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatbot)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PBOT_i)*modelStruct.d_modelVar_one_over_one_minus_PBOT_dX+(-modelStruct.d_modelVar_PBOT_i_dX)*modelStruct.modelVar_one_over_one_minus_PBOT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatbot*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatbot_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*d_umax_dX+modelStruct.d_modelVar_atatbot_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatbot*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatbot_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatbot*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatbot*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATBOT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTBOT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PBOT*((tmp*((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvbot_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvbot)-((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PBOT_dX*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PBOT*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtbot)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtbot)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtbot)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTBOT_i*(((V3*Fmaxr)*Fmaxr)*d_tmp_dX+((V3*Fmaxr)*d_Fmaxr_dX+(V3*d_Fmaxr_dX+d_V3_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTBOT_i_dX*(((V3*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTBOT_i*(((V3*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRBOT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRBOT_i)))
{
if ((modelStruct.modelVar_PBRBOT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
tmp = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvbot));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRBOT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvbot))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRBOT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRBOT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopbot_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.d_modelVar_slopebot_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRBOT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
fbreakdown = (modelStruct.modelVar_fstopbot+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
}
}
d_ijunbot_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LS_i==0.0))
{
d_ijunsti_dX = 0.0;
ijunsti = 0.0;
d_qjunsti_dX = 0.0;
qjunsti = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PSTI==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvsti)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvsti)),modelStruct.modelVar_one_minus_PSTI);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PSTI/(1.0-(vj*modelStruct.modelVar_vbiinvsti))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvsti)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PSTI_dX)));
tmp = value_pow_0;
}
}
d_qjunsti_dX = ((modelStruct.modelVar_qprefsti*(-d_tmp_dX)+modelStruct.d_modelVar_qprefsti_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(d_V3_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2sti_dX*(V3-vj)));
qjunsti = ((modelStruct.modelVar_qprefsti*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(V3-vj)));
d_id_dX = (modelStruct.modelVar_idsatsti*d_idmult_dX+modelStruct.d_modelVar_idsatsti_dX*idmult);
id = (modelStruct.modelVar_idsatsti*idmult);
if (((modelStruct.modelVar_CSRHSTI_i==0.0)&&(modelStruct.modelVar_CTATSTI_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbisti_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbisti-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PSTI_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PSTI_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrsti*d_tmp_dX+modelStruct.d_modelVar_wdepnulrsti_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrsti*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdsti*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdsti_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdsti*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHSTI_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHSTI_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHSTI_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATSTI_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartsti*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PSTI_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PSTI)-(wdep*modelStruct.modelVar_one_minus_PSTI)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartsti_dX*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartsti*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatsti_dX-(0.666666666666667*modelStruct.modelVar_atatsti)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatsti)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PSTI_i)*modelStruct.d_modelVar_one_over_one_minus_PSTI_dX+(-modelStruct.d_modelVar_PSTI_i_dX)*modelStruct.modelVar_one_over_one_minus_PSTI))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatsti*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatsti_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*d_umax_dX+modelStruct.d_modelVar_atatsti_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatsti*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatsti_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatsti*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatsti*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATSTI_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTSTI_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PSTI*((tmp*((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvsti_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvsti)-((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PSTI_dX*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PSTI*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtsti)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtsti)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtsti)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTSTI_i*(((V3*Fmaxr)*Fmaxr)*d_tmp_dX+((V3*Fmaxr)*d_Fmaxr_dX+(V3*d_Fmaxr_dX+d_V3_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTSTI_i_dX*(((V3*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTSTI_i*(((V3*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRSTI_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRSTI_i)))
{
if ((modelStruct.modelVar_PBRSTI_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
tmp = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvsti));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRSTI_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvsti))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRSTI_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRSTI_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopsti_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.d_modelVar_slopesti_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRSTI_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
fbreakdown = (modelStruct.modelVar_fstopsti+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
}
}
d_ijunsti_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LG_i==0.0))
{
d_ijungat_dX = 0.0;
ijungat = 0.0;
d_qjungat_dX = 0.0;
qjungat = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PGAT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvgat)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvgat)),modelStruct.modelVar_one_minus_PGAT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PGAT/(1.0-(vj*modelStruct.modelVar_vbiinvgat))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvgat)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PGAT_dX)));
tmp = value_pow_0;
}
}
d_qjungat_dX = ((modelStruct.modelVar_qprefgat*(-d_tmp_dX)+modelStruct.d_modelVar_qprefgat_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(d_V3_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2gat_dX*(V3-vj)));
qjungat = ((modelStruct.modelVar_qprefgat*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(V3-vj)));
d_id_dX = (modelStruct.modelVar_idsatgat*d_idmult_dX+modelStruct.d_modelVar_idsatgat_dX*idmult);
id = (modelStruct.modelVar_idsatgat*idmult);
if (((modelStruct.modelVar_CSRHGAT_i==0.0)&&(modelStruct.modelVar_CTATGAT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbigat_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbigat-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PGAT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PGAT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrgat*d_tmp_dX+modelStruct.d_modelVar_wdepnulrgat_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrgat*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdgat*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdgat_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdgat*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHGAT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHGAT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHGAT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATGAT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartgat*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PGAT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PGAT)-(wdep*modelStruct.modelVar_one_minus_PGAT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartgat_dX*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartgat*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatgat_dX-(0.666666666666667*modelStruct.modelVar_atatgat)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatgat)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PGAT_i)*modelStruct.d_modelVar_one_over_one_minus_PGAT_dX+(-modelStruct.d_modelVar_PGAT_i_dX)*modelStruct.modelVar_one_over_one_minus_PGAT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatgat*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatgat_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*d_umax_dX+modelStruct.d_modelVar_atatgat_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatgat*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatgat_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatgat*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatgat*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATGAT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTGAT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PGAT*((tmp*((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvgat_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvgat)-((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PGAT_dX*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PGAT*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtgat)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtgat)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtgat)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTGAT_i*(((V3*Fmaxr)*Fmaxr)*d_tmp_dX+((V3*Fmaxr)*d_Fmaxr_dX+(V3*d_Fmaxr_dX+d_V3_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTGAT_i_dX*(((V3*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTGAT_i*(((V3*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRGAT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRGAT_i)))
{
if ((modelStruct.modelVar_PBRGAT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
tmp = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvgat));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRGAT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvgat))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRGAT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRGAT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopgat_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.d_modelVar_slopegat_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRGAT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
fbreakdown = (modelStruct.modelVar_fstopgat+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
}
}
d_ijungat_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
d_I3_dX = (((instanceStruct.instanceVar_AB_i*d_ijunbot_dX+instanceStruct.d_instanceVar_AB_i_dX*ijunbot)+(instanceStruct.instanceVar_LS_i*d_ijunsti_dX+instanceStruct.d_instanceVar_LS_i_dX*ijunsti))+(instanceStruct.instanceVar_LG_i*d_ijungat_dX+instanceStruct.d_instanceVar_LG_i_dX*ijungat));
I3 = (((instanceStruct.instanceVar_AB_i*ijunbot)+(instanceStruct.instanceVar_LS_i*ijunsti))+(instanceStruct.instanceVar_LG_i*ijungat));
d_vbbt_dX = 0.0;
vbbt = 0.0;
d_two_psistar_dX = 0.0;
two_psistar = 0.0;
if ((!(((instanceStruct.instanceVar_AB_i==0.0)&&(instanceStruct.instanceVar_LS_i==0.0))&&(instanceStruct.instanceVar_LG_i==0.0))))
{
d_h1_dX = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.d_instanceVar_vch_dX+4.0*instanceStruct.d_instanceVar_vch_dX*instanceStruct.instanceVar_vch);
h1 = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.instanceVar_vch);
d_h2_dX = ((instanceStruct.instanceVar_vfmin*instanceStruct.d_instanceVar_vch_dX-instanceStruct.instanceVar_vch*instanceStruct.d_instanceVar_vfmin_dX)/instanceStruct.instanceVar_vfmin/instanceStruct.instanceVar_vfmin);
h2 = (instanceStruct.instanceVar_vch/instanceStruct.instanceVar_vfmin);
d_h2d_dX = (instanceStruct.instanceVar_vch*d_h2_dX+instanceStruct.d_instanceVar_vch_dX*h2);
h2d = (V4+(instanceStruct.instanceVar_vch*h2));
d_h3_dX = (instanceStruct.d_instanceVar_vfmin_dX+d_h2d_dX);
h3 = (instanceStruct.instanceVar_vfmin+h2d);
d_h4_dX = (instanceStruct.d_instanceVar_vfmin_dX-d_h2d_dX);
h4 = (instanceStruct.instanceVar_vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_h5_dX = deriv_sqrt_0_d0*(((h4*d_h4_dX+d_h4_dX*h4)+d_h1_dX));
h5 = value_sqrt_0;
}
d_vj_dX = 2.0*(((h3+h5)*V4*instanceStruct.d_instanceVar_vfmin_dX-(V4*instanceStruct.instanceVar_vfmin)*(d_h3_dX+d_h5_dX))/(h3+h5)/(h3+h5));
vj = (2.0*((V4*instanceStruct.instanceVar_vfmin)/(h3+h5)));
if ((V4<instanceStruct.instanceVar_VMAX))
{
if ((fabs((0.5*(V4*modelStruct.modelVar_phitdinv)))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(V4*modelStruct.modelVar_phitdinv)));
double  deriv_exp_0_d0 = value_exp_0;
d_zinv_dX = deriv_exp_0_d0*(0.5*V4*modelStruct.d_modelVar_phitdinv_dX);
zinv = value_exp_0;
}
}
else
{
if (((0.5*(V4*modelStruct.modelVar_phitdinv))<0.0))
{
d_zinv_dX = (-1.0e-100*(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*0.5*(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*(-0.5*V4*modelStruct.d_modelVar_phitdinv_dX)*3.3333333333333333e-01+(-0.5*V4*modelStruct.d_modelVar_phitdinv_dX)*(1.0+(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))+(-0.5*V4*modelStruct.d_modelVar_phitdinv_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V4*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
}
else
{
d_zinv_dX = 1.0e100*(((0.5*(V4*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*(((0.5*(V4*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*V4*modelStruct.d_modelVar_phitdinv_dX*3.3333333333333333e-01+0.5*V4*modelStruct.d_modelVar_phitdinv_dX*(1.0+(((0.5*(V4*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01)))+0.5*V4*modelStruct.d_modelVar_phitdinv_dX*(1.0+(0.5*(((0.5*(V4*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(V4*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))));
zinv = (1.0e100*(1.0+(((0.5*(V4*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(V4*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(V4*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_idmult_dX = (zinv*d_zinv_dX+d_zinv_dX*zinv);
idmult = (zinv*zinv);
}
else
{
d_idmult_dX = ((1.0+((V4-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX+((V4-instanceStruct.instanceVar_VMAX)*modelStruct.d_modelVar_phitdinv_dX+(-instanceStruct.d_instanceVar_VMAX_dX)*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_exp_VMAX_over_phitd);
idmult = ((1.0+((V4-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.instanceVar_exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_zinv_dX = deriv_sqrt_0_d0*(d_idmult_dX);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
d_z_dX = (-d_zinv_dX/zinv/zinv);
z = (1.0/zinv);
if ((V4>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/((2.0+z)+value_sqrt_0));
d_two_psistar_dX = 2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((d_z_dX+deriv_sqrt_0_d0*(((z+1.0)*d_z_dX+d_z_dX*(z+3.0)))))+modelStruct.d_modelVar_phitd_dX*value_log_1);
two_psistar = (2.0*(modelStruct.modelVar_phitd*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/(((2.0*zinv)+1.0)+value_sqrt_0));
d_two_psistar_dX = 2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((2.0*d_zinv_dX+deriv_sqrt_0_d0*(((1.0+zinv)*3.0*d_zinv_dX+d_zinv_dX*(1.0+(3.0*zinv))))))+modelStruct.d_modelVar_phitd_dX*value_log_1);
two_psistar = ((-V4)+(2.0*(modelStruct.modelVar_phitd*value_log_1)));
}
}
d_vjlim_dX = (instanceStruct.d_instanceVar_vbimin_dX-d_two_psistar_dX);
vjlim = (instanceStruct.instanceVar_vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((V4-vjlim)*(V4-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.modelVar_phitd)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vjsrh_dX = 0.5*(d_vjlim_dX-deriv_sqrt_0_d0*((((V4-vjlim)*(-d_vjlim_dX)+(-d_vjlim_dX)*(V4-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.d_modelVar_phitd_dX+4.0*modelStruct.d_modelVar_phitd_dX*modelStruct.modelVar_phitd))));
vjsrh = (0.5*((V4+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V4-instanceStruct.instanceVar_vbbtlim)*(V4-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.modelVar_phitr)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vbbt_dX = 0.5*(instanceStruct.d_instanceVar_vbbtlim_dX-deriv_sqrt_0_d0*((((V4-instanceStruct.instanceVar_vbbtlim)*(-instanceStruct.d_instanceVar_vbbtlim_dX)+(-instanceStruct.d_instanceVar_vbbtlim_dX)*(V4-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.d_modelVar_phitr_dX+4.0*modelStruct.d_modelVar_phitr_dX*modelStruct.modelVar_phitr))));
vbbt = (0.5*((V4+instanceStruct.instanceVar_vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V4)*(V4))+((4.0*1.0e-6)*1.0e-6)));
d_vav_dX = 0.0;
vav = (0.5*(V4-value_sqrt_0));
}
}
if ((instanceStruct.instanceVar_AB_i==0.0))
{
d_ijunbot_dX = 0.0;
ijunbot = 0.0;
d_qjunbot_dX = 0.0;
qjunbot = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PBOT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvbot)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvbot)),modelStruct.modelVar_one_minus_PBOT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PBOT/(1.0-(vj*modelStruct.modelVar_vbiinvbot))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvbot)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PBOT_dX)));
tmp = value_pow_0;
}
}
d_qjunbot_dX = ((modelStruct.modelVar_qprefbot*(-d_tmp_dX)+modelStruct.d_modelVar_qprefbot_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(-d_vj_dX)+modelStruct.d_modelVar_qpref2bot_dX*(V4-vj)));
qjunbot = ((modelStruct.modelVar_qprefbot*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(V4-vj)));
d_id_dX = (modelStruct.modelVar_idsatbot*d_idmult_dX+modelStruct.d_modelVar_idsatbot_dX*idmult);
id = (modelStruct.modelVar_idsatbot*idmult);
if (((modelStruct.modelVar_CSRHBOT_i==0.0)&&(modelStruct.modelVar_CTATBOT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbibot_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbibot-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PBOT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PBOT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrbot*d_tmp_dX+modelStruct.d_modelVar_wdepnulrbot_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrbot*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdbot*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdbot_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdbot*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHBOT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHBOT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHBOT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATBOT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartbot*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PBOT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PBOT)-(wdep*modelStruct.modelVar_one_minus_PBOT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartbot_dX*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartbot*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatbot_dX-(0.666666666666667*modelStruct.modelVar_atatbot)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatbot)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PBOT_i)*modelStruct.d_modelVar_one_over_one_minus_PBOT_dX+(-modelStruct.d_modelVar_PBOT_i_dX)*modelStruct.modelVar_one_over_one_minus_PBOT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatbot*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatbot_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*d_umax_dX+modelStruct.d_modelVar_atatbot_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatbot*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatbot_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatbot*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatbot*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATBOT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTBOT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PBOT*((tmp*((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvbot_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvbot)-((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PBOT_dX*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PBOT*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtbot)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtbot)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtbot)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTBOT_i*(((V4*Fmaxr)*Fmaxr)*d_tmp_dX+((V4*Fmaxr)*d_Fmaxr_dX+V4*d_Fmaxr_dX*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTBOT_i_dX*(((V4*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTBOT_i*(((V4*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRBOT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRBOT_i)))
{
if ((modelStruct.modelVar_PBRBOT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
tmp = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvbot));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRBOT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvbot))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRBOT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRBOT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopbot_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.d_modelVar_slopebot_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRBOT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
fbreakdown = (modelStruct.modelVar_fstopbot+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
}
}
d_ijunbot_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LS_i==0.0))
{
d_ijunsti_dX = 0.0;
ijunsti = 0.0;
d_qjunsti_dX = 0.0;
qjunsti = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PSTI==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvsti)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvsti)),modelStruct.modelVar_one_minus_PSTI);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PSTI/(1.0-(vj*modelStruct.modelVar_vbiinvsti))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvsti)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PSTI_dX)));
tmp = value_pow_0;
}
}
d_qjunsti_dX = ((modelStruct.modelVar_qprefsti*(-d_tmp_dX)+modelStruct.d_modelVar_qprefsti_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(-d_vj_dX)+modelStruct.d_modelVar_qpref2sti_dX*(V4-vj)));
qjunsti = ((modelStruct.modelVar_qprefsti*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(V4-vj)));
d_id_dX = (modelStruct.modelVar_idsatsti*d_idmult_dX+modelStruct.d_modelVar_idsatsti_dX*idmult);
id = (modelStruct.modelVar_idsatsti*idmult);
if (((modelStruct.modelVar_CSRHSTI_i==0.0)&&(modelStruct.modelVar_CTATSTI_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbisti_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbisti-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PSTI_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PSTI_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrsti*d_tmp_dX+modelStruct.d_modelVar_wdepnulrsti_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrsti*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdsti*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdsti_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdsti*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHSTI_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHSTI_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHSTI_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATSTI_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartsti*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PSTI_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PSTI)-(wdep*modelStruct.modelVar_one_minus_PSTI)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartsti_dX*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartsti*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatsti_dX-(0.666666666666667*modelStruct.modelVar_atatsti)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatsti)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PSTI_i)*modelStruct.d_modelVar_one_over_one_minus_PSTI_dX+(-modelStruct.d_modelVar_PSTI_i_dX)*modelStruct.modelVar_one_over_one_minus_PSTI))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatsti*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatsti_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*d_umax_dX+modelStruct.d_modelVar_atatsti_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatsti*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatsti_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatsti*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatsti*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATSTI_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTSTI_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PSTI*((tmp*((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvsti_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvsti)-((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PSTI_dX*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PSTI*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtsti)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtsti)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtsti)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTSTI_i*(((V4*Fmaxr)*Fmaxr)*d_tmp_dX+((V4*Fmaxr)*d_Fmaxr_dX+V4*d_Fmaxr_dX*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTSTI_i_dX*(((V4*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTSTI_i*(((V4*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRSTI_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRSTI_i)))
{
if ((modelStruct.modelVar_PBRSTI_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
tmp = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvsti));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRSTI_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvsti))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRSTI_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRSTI_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopsti_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.d_modelVar_slopesti_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRSTI_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
fbreakdown = (modelStruct.modelVar_fstopsti+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
}
}
d_ijunsti_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LG_i==0.0))
{
d_ijungat_dX = 0.0;
ijungat = 0.0;
d_qjungat_dX = 0.0;
qjungat = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PGAT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvgat)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvgat)),modelStruct.modelVar_one_minus_PGAT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PGAT/(1.0-(vj*modelStruct.modelVar_vbiinvgat))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvgat)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PGAT_dX)));
tmp = value_pow_0;
}
}
d_qjungat_dX = ((modelStruct.modelVar_qprefgat*(-d_tmp_dX)+modelStruct.d_modelVar_qprefgat_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(-d_vj_dX)+modelStruct.d_modelVar_qpref2gat_dX*(V4-vj)));
qjungat = ((modelStruct.modelVar_qprefgat*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(V4-vj)));
d_id_dX = (modelStruct.modelVar_idsatgat*d_idmult_dX+modelStruct.d_modelVar_idsatgat_dX*idmult);
id = (modelStruct.modelVar_idsatgat*idmult);
if (((modelStruct.modelVar_CSRHGAT_i==0.0)&&(modelStruct.modelVar_CTATGAT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbigat_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbigat-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PGAT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PGAT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrgat*d_tmp_dX+modelStruct.d_modelVar_wdepnulrgat_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrgat*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdgat*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdgat_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdgat*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHGAT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHGAT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHGAT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATGAT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartgat*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PGAT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PGAT)-(wdep*modelStruct.modelVar_one_minus_PGAT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartgat_dX*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartgat*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatgat_dX-(0.666666666666667*modelStruct.modelVar_atatgat)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatgat)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PGAT_i)*modelStruct.d_modelVar_one_over_one_minus_PGAT_dX+(-modelStruct.d_modelVar_PGAT_i_dX)*modelStruct.modelVar_one_over_one_minus_PGAT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatgat*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatgat_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*d_umax_dX+modelStruct.d_modelVar_atatgat_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatgat*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatgat_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatgat*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatgat*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATGAT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTGAT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PGAT*((tmp*((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvgat_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvgat)-((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PGAT_dX*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PGAT*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtgat)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtgat)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtgat)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTGAT_i*(((V4*Fmaxr)*Fmaxr)*d_tmp_dX+((V4*Fmaxr)*d_Fmaxr_dX+V4*d_Fmaxr_dX*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTGAT_i_dX*(((V4*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTGAT_i*(((V4*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRGAT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRGAT_i)))
{
if ((modelStruct.modelVar_PBRGAT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
tmp = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvgat));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRGAT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvgat))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRGAT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRGAT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopgat_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.d_modelVar_slopegat_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRGAT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
fbreakdown = (modelStruct.modelVar_fstopgat+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
}
}
d_ijungat_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
d_I4_dX = (((instanceStruct.instanceVar_AB_i*d_ijunbot_dX+instanceStruct.d_instanceVar_AB_i_dX*ijunbot)+(instanceStruct.instanceVar_LS_i*d_ijunsti_dX+instanceStruct.d_instanceVar_LS_i_dX*ijunsti))+(instanceStruct.instanceVar_LG_i*d_ijungat_dX+instanceStruct.d_instanceVar_LG_i_dX*ijungat));
I4 = (((instanceStruct.instanceVar_AB_i*ijunbot)+(instanceStruct.instanceVar_LS_i*ijunsti))+(instanceStruct.instanceVar_LG_i*ijungat));
d_vbbt_dX = 0.0;
vbbt = 0.0;
d_two_psistar_dX = 0.0;
two_psistar = 0.0;
if ((!(((instanceStruct.instanceVar_AB_i==0.0)&&(instanceStruct.instanceVar_LS_i==0.0))&&(instanceStruct.instanceVar_LG_i==0.0))))
{
d_h1_dX = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.d_instanceVar_vch_dX+4.0*instanceStruct.d_instanceVar_vch_dX*instanceStruct.instanceVar_vch);
h1 = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.instanceVar_vch);
d_h2_dX = ((instanceStruct.instanceVar_vfmin*instanceStruct.d_instanceVar_vch_dX-instanceStruct.instanceVar_vch*instanceStruct.d_instanceVar_vfmin_dX)/instanceStruct.instanceVar_vfmin/instanceStruct.instanceVar_vfmin);
h2 = (instanceStruct.instanceVar_vch/instanceStruct.instanceVar_vfmin);
d_h2d_dX = (instanceStruct.instanceVar_vch*d_h2_dX+instanceStruct.d_instanceVar_vch_dX*h2);
h2d = (V5+(instanceStruct.instanceVar_vch*h2));
d_h3_dX = (instanceStruct.d_instanceVar_vfmin_dX+d_h2d_dX);
h3 = (instanceStruct.instanceVar_vfmin+h2d);
d_h4_dX = (instanceStruct.d_instanceVar_vfmin_dX-d_h2d_dX);
h4 = (instanceStruct.instanceVar_vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_h5_dX = deriv_sqrt_0_d0*(((h4*d_h4_dX+d_h4_dX*h4)+d_h1_dX));
h5 = value_sqrt_0;
}
d_vj_dX = 2.0*(((h3+h5)*V5*instanceStruct.d_instanceVar_vfmin_dX-(V5*instanceStruct.instanceVar_vfmin)*(d_h3_dX+d_h5_dX))/(h3+h5)/(h3+h5));
vj = (2.0*((V5*instanceStruct.instanceVar_vfmin)/(h3+h5)));
if ((V5<instanceStruct.instanceVar_VMAX))
{
if ((fabs((0.5*(V5*modelStruct.modelVar_phitdinv)))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(V5*modelStruct.modelVar_phitdinv)));
double  deriv_exp_0_d0 = value_exp_0;
d_zinv_dX = deriv_exp_0_d0*(0.5*V5*modelStruct.d_modelVar_phitdinv_dX);
zinv = value_exp_0;
}
}
else
{
if (((0.5*(V5*modelStruct.modelVar_phitdinv))<0.0))
{
d_zinv_dX = (-1.0e-100*(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*0.5*(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*(-0.5*V5*modelStruct.d_modelVar_phitdinv_dX)*3.3333333333333333e-01+(-0.5*V5*modelStruct.d_modelVar_phitdinv_dX)*(1.0+(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))+(-0.5*V5*modelStruct.d_modelVar_phitdinv_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(V5*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
}
else
{
d_zinv_dX = 1.0e100*(((0.5*(V5*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*(((0.5*(V5*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*V5*modelStruct.d_modelVar_phitdinv_dX*3.3333333333333333e-01+0.5*V5*modelStruct.d_modelVar_phitdinv_dX*(1.0+(((0.5*(V5*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01)))+0.5*V5*modelStruct.d_modelVar_phitdinv_dX*(1.0+(0.5*(((0.5*(V5*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(V5*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))));
zinv = (1.0e100*(1.0+(((0.5*(V5*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(V5*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(V5*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_idmult_dX = (zinv*d_zinv_dX+d_zinv_dX*zinv);
idmult = (zinv*zinv);
}
else
{
d_idmult_dX = ((1.0+((V5-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX+((V5-instanceStruct.instanceVar_VMAX)*modelStruct.d_modelVar_phitdinv_dX+(-instanceStruct.d_instanceVar_VMAX_dX)*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_exp_VMAX_over_phitd);
idmult = ((1.0+((V5-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.instanceVar_exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_zinv_dX = deriv_sqrt_0_d0*(d_idmult_dX);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
d_z_dX = (-d_zinv_dX/zinv/zinv);
z = (1.0/zinv);
if ((V5>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/((2.0+z)+value_sqrt_0));
d_two_psistar_dX = 2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((d_z_dX+deriv_sqrt_0_d0*(((z+1.0)*d_z_dX+d_z_dX*(z+3.0)))))+modelStruct.d_modelVar_phitd_dX*value_log_1);
two_psistar = (2.0*(modelStruct.modelVar_phitd*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/(((2.0*zinv)+1.0)+value_sqrt_0));
d_two_psistar_dX = 2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((2.0*d_zinv_dX+deriv_sqrt_0_d0*(((1.0+zinv)*3.0*d_zinv_dX+d_zinv_dX*(1.0+(3.0*zinv))))))+modelStruct.d_modelVar_phitd_dX*value_log_1);
two_psistar = ((-V5)+(2.0*(modelStruct.modelVar_phitd*value_log_1)));
}
}
d_vjlim_dX = (instanceStruct.d_instanceVar_vbimin_dX-d_two_psistar_dX);
vjlim = (instanceStruct.instanceVar_vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((V5-vjlim)*(V5-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.modelVar_phitd)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vjsrh_dX = 0.5*(d_vjlim_dX-deriv_sqrt_0_d0*((((V5-vjlim)*(-d_vjlim_dX)+(-d_vjlim_dX)*(V5-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.d_modelVar_phitd_dX+4.0*modelStruct.d_modelVar_phitd_dX*modelStruct.modelVar_phitd))));
vjsrh = (0.5*((V5+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V5-instanceStruct.instanceVar_vbbtlim)*(V5-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.modelVar_phitr)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vbbt_dX = 0.5*(instanceStruct.d_instanceVar_vbbtlim_dX-deriv_sqrt_0_d0*((((V5-instanceStruct.instanceVar_vbbtlim)*(-instanceStruct.d_instanceVar_vbbtlim_dX)+(-instanceStruct.d_instanceVar_vbbtlim_dX)*(V5-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.d_modelVar_phitr_dX+4.0*modelStruct.d_modelVar_phitr_dX*modelStruct.modelVar_phitr))));
vbbt = (0.5*((V5+instanceStruct.instanceVar_vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((V5)*(V5))+((4.0*1.0e-6)*1.0e-6)));
d_vav_dX = 0.0;
vav = (0.5*(V5-value_sqrt_0));
}
}
if ((instanceStruct.instanceVar_AB_i==0.0))
{
d_ijunbot_dX = 0.0;
ijunbot = 0.0;
d_qjunbot_dX = 0.0;
qjunbot = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PBOT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvbot)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvbot)),modelStruct.modelVar_one_minus_PBOT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PBOT/(1.0-(vj*modelStruct.modelVar_vbiinvbot))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvbot)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PBOT_dX)));
tmp = value_pow_0;
}
}
d_qjunbot_dX = ((modelStruct.modelVar_qprefbot*(-d_tmp_dX)+modelStruct.d_modelVar_qprefbot_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(-d_vj_dX)+modelStruct.d_modelVar_qpref2bot_dX*(V5-vj)));
qjunbot = ((modelStruct.modelVar_qprefbot*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(V5-vj)));
d_id_dX = (modelStruct.modelVar_idsatbot*d_idmult_dX+modelStruct.d_modelVar_idsatbot_dX*idmult);
id = (modelStruct.modelVar_idsatbot*idmult);
if (((modelStruct.modelVar_CSRHBOT_i==0.0)&&(modelStruct.modelVar_CTATBOT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbibot_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbibot-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PBOT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PBOT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrbot*d_tmp_dX+modelStruct.d_modelVar_wdepnulrbot_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrbot*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdbot*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdbot_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdbot*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHBOT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHBOT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHBOT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATBOT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartbot*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PBOT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PBOT)-(wdep*modelStruct.modelVar_one_minus_PBOT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartbot_dX*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartbot*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatbot_dX-(0.666666666666667*modelStruct.modelVar_atatbot)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatbot)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PBOT_i)*modelStruct.d_modelVar_one_over_one_minus_PBOT_dX+(-modelStruct.d_modelVar_PBOT_i_dX)*modelStruct.modelVar_one_over_one_minus_PBOT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatbot*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatbot_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*d_umax_dX+modelStruct.d_modelVar_atatbot_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatbot*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatbot_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatbot*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatbot*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATBOT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTBOT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PBOT*((tmp*((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvbot_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvbot)-((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PBOT_dX*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PBOT*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtbot)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtbot)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtbot)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTBOT_i*(((V5*Fmaxr)*Fmaxr)*d_tmp_dX+((V5*Fmaxr)*d_Fmaxr_dX+V5*d_Fmaxr_dX*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTBOT_i_dX*(((V5*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTBOT_i*(((V5*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRBOT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRBOT_i)))
{
if ((modelStruct.modelVar_PBRBOT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
tmp = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvbot));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRBOT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvbot))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRBOT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRBOT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopbot_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.d_modelVar_slopebot_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRBOT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
fbreakdown = (modelStruct.modelVar_fstopbot+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
}
}
d_ijunbot_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LS_i==0.0))
{
d_ijunsti_dX = 0.0;
ijunsti = 0.0;
d_qjunsti_dX = 0.0;
qjunsti = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PSTI==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvsti)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvsti)),modelStruct.modelVar_one_minus_PSTI);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PSTI/(1.0-(vj*modelStruct.modelVar_vbiinvsti))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvsti)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PSTI_dX)));
tmp = value_pow_0;
}
}
d_qjunsti_dX = ((modelStruct.modelVar_qprefsti*(-d_tmp_dX)+modelStruct.d_modelVar_qprefsti_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(-d_vj_dX)+modelStruct.d_modelVar_qpref2sti_dX*(V5-vj)));
qjunsti = ((modelStruct.modelVar_qprefsti*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(V5-vj)));
d_id_dX = (modelStruct.modelVar_idsatsti*d_idmult_dX+modelStruct.d_modelVar_idsatsti_dX*idmult);
id = (modelStruct.modelVar_idsatsti*idmult);
if (((modelStruct.modelVar_CSRHSTI_i==0.0)&&(modelStruct.modelVar_CTATSTI_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbisti_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbisti-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PSTI_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PSTI_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrsti*d_tmp_dX+modelStruct.d_modelVar_wdepnulrsti_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrsti*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdsti*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdsti_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdsti*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHSTI_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHSTI_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHSTI_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATSTI_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartsti*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PSTI_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PSTI)-(wdep*modelStruct.modelVar_one_minus_PSTI)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartsti_dX*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartsti*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatsti_dX-(0.666666666666667*modelStruct.modelVar_atatsti)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatsti)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PSTI_i)*modelStruct.d_modelVar_one_over_one_minus_PSTI_dX+(-modelStruct.d_modelVar_PSTI_i_dX)*modelStruct.modelVar_one_over_one_minus_PSTI))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatsti*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatsti_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*d_umax_dX+modelStruct.d_modelVar_atatsti_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatsti*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatsti_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatsti*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatsti*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATSTI_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTSTI_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PSTI*((tmp*((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvsti_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvsti)-((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PSTI_dX*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PSTI*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtsti)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtsti)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtsti)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTSTI_i*(((V5*Fmaxr)*Fmaxr)*d_tmp_dX+((V5*Fmaxr)*d_Fmaxr_dX+V5*d_Fmaxr_dX*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTSTI_i_dX*(((V5*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTSTI_i*(((V5*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRSTI_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRSTI_i)))
{
if ((modelStruct.modelVar_PBRSTI_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
tmp = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvsti));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRSTI_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvsti))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRSTI_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRSTI_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopsti_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.d_modelVar_slopesti_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRSTI_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
fbreakdown = (modelStruct.modelVar_fstopsti+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
}
}
d_ijunsti_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LG_i==0.0))
{
d_ijungat_dX = 0.0;
ijungat = 0.0;
d_qjungat_dX = 0.0;
qjungat = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PGAT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvgat)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvgat)),modelStruct.modelVar_one_minus_PGAT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PGAT/(1.0-(vj*modelStruct.modelVar_vbiinvgat))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvgat)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PGAT_dX)));
tmp = value_pow_0;
}
}
d_qjungat_dX = ((modelStruct.modelVar_qprefgat*(-d_tmp_dX)+modelStruct.d_modelVar_qprefgat_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(-d_vj_dX)+modelStruct.d_modelVar_qpref2gat_dX*(V5-vj)));
qjungat = ((modelStruct.modelVar_qprefgat*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(V5-vj)));
d_id_dX = (modelStruct.modelVar_idsatgat*d_idmult_dX+modelStruct.d_modelVar_idsatgat_dX*idmult);
id = (modelStruct.modelVar_idsatgat*idmult);
if (((modelStruct.modelVar_CSRHGAT_i==0.0)&&(modelStruct.modelVar_CTATGAT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbigat_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbigat-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PGAT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PGAT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrgat*d_tmp_dX+modelStruct.d_modelVar_wdepnulrgat_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrgat*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdgat*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdgat_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdgat*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHGAT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHGAT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHGAT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATGAT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartgat*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PGAT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PGAT)-(wdep*modelStruct.modelVar_one_minus_PGAT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartgat_dX*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartgat*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatgat_dX-(0.666666666666667*modelStruct.modelVar_atatgat)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatgat)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PGAT_i)*modelStruct.d_modelVar_one_over_one_minus_PGAT_dX+(-modelStruct.d_modelVar_PGAT_i_dX)*modelStruct.modelVar_one_over_one_minus_PGAT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatgat*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatgat_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*d_umax_dX+modelStruct.d_modelVar_atatgat_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatgat*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatgat_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatgat*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatgat*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATGAT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTGAT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PGAT*((tmp*((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvgat_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvgat)-((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PGAT_dX*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PGAT*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtgat)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtgat)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtgat)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTGAT_i*(((V5*Fmaxr)*Fmaxr)*d_tmp_dX+((V5*Fmaxr)*d_Fmaxr_dX+V5*d_Fmaxr_dX*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTGAT_i_dX*(((V5*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTGAT_i*(((V5*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRGAT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRGAT_i)))
{
if ((modelStruct.modelVar_PBRGAT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
tmp = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvgat));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRGAT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvgat))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRGAT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRGAT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopgat_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.d_modelVar_slopegat_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRGAT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
fbreakdown = (modelStruct.modelVar_fstopgat+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
}
}
d_ijungat_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
d_I5_dX = (((instanceStruct.instanceVar_AB_i*d_ijunbot_dX+instanceStruct.d_instanceVar_AB_i_dX*ijunbot)+(instanceStruct.instanceVar_LS_i*d_ijunsti_dX+instanceStruct.d_instanceVar_LS_i_dX*ijunsti))+(instanceStruct.instanceVar_LG_i*d_ijungat_dX+instanceStruct.d_instanceVar_LG_i_dX*ijungat));
I5 = (((instanceStruct.instanceVar_AB_i*ijunbot)+(instanceStruct.instanceVar_LS_i*ijunsti))+(instanceStruct.instanceVar_LG_i*ijungat));
instanceStruct.d_instanceVar_ISATFOR1_dX = (((instanceStruct.instanceVar_AB_i*modelStruct.d_modelVar_idsatbot_dX+instanceStruct.d_instanceVar_AB_i_dX*modelStruct.modelVar_idsatbot)+(instanceStruct.instanceVar_LS_i*modelStruct.d_modelVar_idsatsti_dX+instanceStruct.d_instanceVar_LS_i_dX*modelStruct.modelVar_idsatsti))+(instanceStruct.instanceVar_LG_i*modelStruct.d_modelVar_idsatgat_dX+instanceStruct.d_instanceVar_LG_i_dX*modelStruct.modelVar_idsatgat));
instanceStruct.instanceVar_ISATFOR1 = (((instanceStruct.instanceVar_AB_i*modelStruct.modelVar_idsatbot)+(instanceStruct.instanceVar_LS_i*modelStruct.modelVar_idsatsti))+(instanceStruct.instanceVar_LG_i*modelStruct.modelVar_idsatgat));
{
double value_exp_0 = exp(((V4*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR1));
double  deriv_exp_0_d0 = value_exp_0;
d_I4_cor_dX = (d_I4_dX-(instanceStruct.instanceVar_ISATFOR1*deriv_exp_0_d0*(V4*modelStruct.d_modelVar_phitdinv_dX*instanceStruct.instanceVar_MFOR1)+instanceStruct.d_instanceVar_ISATFOR1_dX*(value_exp_0-1.0)));
I4_cor = (I4-(instanceStruct.instanceVar_ISATFOR1*(value_exp_0-1.0)));
}
{
double value_exp_0 = exp(((V5*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR1));
double  deriv_exp_0_d0 = value_exp_0;
d_I5_cor_dX = (d_I5_dX-(instanceStruct.instanceVar_ISATFOR1*deriv_exp_0_d0*(V5*modelStruct.d_modelVar_phitdinv_dX*instanceStruct.instanceVar_MFOR1)+instanceStruct.d_instanceVar_ISATFOR1_dX*(value_exp_0-1.0)));
I5_cor = (I5-(instanceStruct.instanceVar_ISATFOR1*(value_exp_0-1.0)));
}
if ((!(((instanceStruct.instanceVar_AB_i==0.0)&&(instanceStruct.instanceVar_LS_i==0.0))&&(instanceStruct.instanceVar_LG_i==0.0))))
{
if (((I4>0.0)&&(I5>0.0)))
{
if ((((((I4_cor/I4)>1.0e-3)||((I5_cor/I5)>1.0e-3))&&(I4_cor>0.0))&&(I5_cor>0.0)))
{
d_alphaje_dX = ((I5_cor*d_I4_cor_dX-I4_cor*d_I5_cor_dX)/I5_cor/I5_cor);
alphaje = (I4_cor/I5_cor);
{
double value_log_0 = log(alphaje);
double  deriv_log_0_d0 = (1.0/alphaje);
instanceStruct.d_instanceVar_MFOR2_dX = ((modelStruct.modelVar_phitd*deriv_log_0_d0*(d_alphaje_dX)+modelStruct.d_modelVar_phitd_dX*value_log_0)/(V4-V5));
instanceStruct.instanceVar_MFOR2 = ((modelStruct.modelVar_phitd*value_log_0)/(V4-V5));
}
{
double value_exp_0 = exp(((V4*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR2));
double  deriv_exp_0_d0 = value_exp_0;
instanceStruct.d_instanceVar_ISATFOR2_dX = (((value_exp_0-1.0)*d_I4_cor_dX-I4_cor*deriv_exp_0_d0*(((V4*modelStruct.modelVar_phitdinv)*instanceStruct.d_instanceVar_MFOR2_dX+V4*modelStruct.d_modelVar_phitdinv_dX*instanceStruct.instanceVar_MFOR2)))/(value_exp_0-1.0)/(value_exp_0-1.0));
instanceStruct.instanceVar_ISATFOR2 = (I4_cor/(value_exp_0-1.0));
}
}
}
{
double value_exp_0 = exp(((V1*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR1));
double value_exp_1 = exp(((V1*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR2));
double  deriv_exp_0_d0 = value_exp_0;
double  deriv_exp_1_d0 = value_exp_1;
d_I1_cor_dX = ((d_I1_dX-(instanceStruct.instanceVar_ISATFOR1*deriv_exp_0_d0*((V1*modelStruct.d_modelVar_phitdinv_dX+d_V1_dX*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR1)+instanceStruct.d_instanceVar_ISATFOR1_dX*(value_exp_0-1.0)))-(instanceStruct.instanceVar_ISATFOR2*deriv_exp_1_d0*(((V1*modelStruct.modelVar_phitdinv)*instanceStruct.d_instanceVar_MFOR2_dX+(V1*modelStruct.d_modelVar_phitdinv_dX+d_V1_dX*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR2))+instanceStruct.d_instanceVar_ISATFOR2_dX*(value_exp_1-1.0)));
I1_cor = ((I1-(instanceStruct.instanceVar_ISATFOR1*(value_exp_0-1.0)))-(instanceStruct.instanceVar_ISATFOR2*(value_exp_1-1.0)));
}
{
double value_exp_0 = exp(((V2*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR1));
double value_exp_1 = exp(((V2*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR2));
double  deriv_exp_0_d0 = value_exp_0;
double  deriv_exp_1_d0 = value_exp_1;
d_I2_cor_dX = ((d_I2_dX-(instanceStruct.instanceVar_ISATFOR1*deriv_exp_0_d0*((V2*modelStruct.d_modelVar_phitdinv_dX+d_V2_dX*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR1)+instanceStruct.d_instanceVar_ISATFOR1_dX*(value_exp_0-1.0)))-(instanceStruct.instanceVar_ISATFOR2*deriv_exp_1_d0*(((V2*modelStruct.modelVar_phitdinv)*instanceStruct.d_instanceVar_MFOR2_dX+(V2*modelStruct.d_modelVar_phitdinv_dX+d_V2_dX*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR2))+instanceStruct.d_instanceVar_ISATFOR2_dX*(value_exp_1-1.0)));
I2_cor = ((I2-(instanceStruct.instanceVar_ISATFOR1*(value_exp_0-1.0)))-(instanceStruct.instanceVar_ISATFOR2*(value_exp_1-1.0)));
}
{
double value_exp_0 = exp(((V3*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR1));
double value_exp_1 = exp(((V3*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR2));
double  deriv_exp_0_d0 = value_exp_0;
double  deriv_exp_1_d0 = value_exp_1;
d_I3_cor_dX = ((d_I3_dX-(instanceStruct.instanceVar_ISATFOR1*deriv_exp_0_d0*((V3*modelStruct.d_modelVar_phitdinv_dX+d_V3_dX*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR1)+instanceStruct.d_instanceVar_ISATFOR1_dX*(value_exp_0-1.0)))-(instanceStruct.instanceVar_ISATFOR2*deriv_exp_1_d0*(((V3*modelStruct.modelVar_phitdinv)*instanceStruct.d_instanceVar_MFOR2_dX+(V3*modelStruct.d_modelVar_phitdinv_dX+d_V3_dX*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR2))+instanceStruct.d_instanceVar_ISATFOR2_dX*(value_exp_1-1.0)));
I3_cor = ((I3-(instanceStruct.instanceVar_ISATFOR1*(value_exp_0-1.0)))-(instanceStruct.instanceVar_ISATFOR2*(value_exp_1-1.0)));
}
if ((((I1<0.0)&&(I2<0.0))&&(I3<0.0)))
{
if ((((((((I1_cor/I1)>1.0e-3)||((I2_cor/I2)>1.0e-3))||((I3_cor/I3)>1.0e-3))&&(I1_cor<0.0))&&(I2_cor<0.0))&&(I3_cor<0.0)))
{
d_alphaje_dX = ((I2_cor*d_I1_cor_dX-I1_cor*d_I2_cor_dX)/I2_cor/I2_cor);
alphaje = (I1_cor/I2_cor);
{
double value_log_0 = log(alphaje);
double  deriv_log_0_d0 = (1.0/alphaje);
d_m0_rev_dX = (((V1-V2)*((-modelStruct.modelVar_phitd)*deriv_log_0_d0*(d_alphaje_dX)+(-modelStruct.d_modelVar_phitd_dX)*value_log_0)-((-modelStruct.modelVar_phitd)*value_log_0)*(d_V1_dX-d_V2_dX))/(V1-V2)/(V1-V2));
m0_rev = (((-modelStruct.modelVar_phitd)*value_log_0)/(V1-V2));
}
d_tt0_dX = (((V2-V1)*d_V2_dX-V2*(d_V2_dX-d_V1_dX))/(V2-V1)/(V2-V1));
tt0 = (V2/(V2-V1));
{
double value_pow_0 = pow(alphaje,tt0);
double  deriv_pow_0_d0 = ((alphaje == 0.0)?0.0:(value_pow_0*tt0/alphaje));
double  deriv_pow_0_d1 = (alphaje == 0.0)?0.0:(log(alphaje)*value_pow_0);
d_tt1_dX = ((modelStruct.modelVar_phitd*(alphaje-1.0))*((deriv_pow_0_d0*(d_alphaje_dX))+(deriv_pow_0_d1*(d_tt0_dX)))+(modelStruct.modelVar_phitd*d_alphaje_dX+modelStruct.d_modelVar_phitd_dX*(alphaje-1.0))*(value_pow_0-1.0));
tt1 = ((modelStruct.modelVar_phitd*(alphaje-1.0))*(value_pow_0-1.0));
}
d_tt0_dX = (((V1-V2)*d_V1_dX-V1*(d_V1_dX-d_V2_dX))/(V1-V2)/(V1-V2));
tt0 = (V1/(V1-V2));
{
double value_pow_0 = pow(alphaje,tt0);
double  deriv_pow_0_d0 = ((alphaje == 0.0)?0.0:(value_pow_0*tt0/alphaje));
double  deriv_pow_0_d1 = (alphaje == 0.0)?0.0:(log(alphaje)*value_pow_0);
d_tt2_dX = (((value_pow_0*(d_V2_dX-d_V1_dX)+((deriv_pow_0_d0*(d_alphaje_dX))+(deriv_pow_0_d1*(d_tt0_dX)))*(V2-V1))+(alphaje*d_V1_dX+d_alphaje_dX*V1))-d_V2_dX);
tt2 = (((value_pow_0*(V2-V1))+(alphaje*V1))-V2);
}
d_mcor_rev_dX = ((tt2*d_tt1_dX-tt1*d_tt2_dX)/tt2/tt2);
mcor_rev = (tt1/tt2);
instanceStruct.d_instanceVar_MREV_dX = (d_m0_rev_dX+d_mcor_rev_dX);
instanceStruct.instanceVar_MREV = (m0_rev+mcor_rev);
if ((fabs(((V3*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MREV))<1.0e-6))
{
instanceStruct.instanceVar_m0flag = 1.0;
instanceStruct.d_instanceVar_ISATREV_dX = (I3_cor*((-d_V3_dX/V3/V3)+((0.5*modelStruct.modelVar_phitdinv)*instanceStruct.d_instanceVar_MREV_dX+0.5*modelStruct.d_modelVar_phitdinv_dX*instanceStruct.instanceVar_MREV))+d_I3_cor_dX*((1.0/V3)+((0.5*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MREV)));
instanceStruct.instanceVar_ISATREV = (I3_cor*((1.0/V3)+((0.5*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MREV)));
instanceStruct.d_instanceVar_MREV_dX = ((V3*((((-0.5)*I3_cor)*instanceStruct.instanceVar_MREV)*modelStruct.d_modelVar_phitdinv_dX+(((-0.5)*I3_cor)*instanceStruct.d_instanceVar_MREV_dX+(-0.5)*d_I3_cor_dX*instanceStruct.instanceVar_MREV)*modelStruct.modelVar_phitdinv)-((((-0.5)*I3_cor)*instanceStruct.instanceVar_MREV)*modelStruct.modelVar_phitdinv)*d_V3_dX)/V3/V3);
instanceStruct.instanceVar_MREV = (((((-0.5)*I3_cor)*instanceStruct.instanceVar_MREV)*modelStruct.modelVar_phitdinv)/V3);
}
else
{
instanceStruct.instanceVar_m0flag = 0.0;
{
double value_exp_0 = exp((((-V3)*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MREV));
double  deriv_exp_0_d0 = value_exp_0;
instanceStruct.d_instanceVar_ISATREV_dX = (((value_exp_0-1.0)*(-d_I3_cor_dX)-(-I3_cor)*deriv_exp_0_d0*((((-V3)*modelStruct.modelVar_phitdinv)*instanceStruct.d_instanceVar_MREV_dX+((-V3)*modelStruct.d_modelVar_phitdinv_dX+(-d_V3_dX)*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MREV)))/(value_exp_0-1.0)/(value_exp_0-1.0));
instanceStruct.instanceVar_ISATREV = ((-I3_cor)/(value_exp_0-1.0));
}
}
}
}
}
d_zfrac_dX = (modelStruct.modelVar_FJUNQ_i*(((instanceStruct.instanceVar_AB_i*modelStruct.d_modelVar_cjobot_dX+instanceStruct.d_instanceVar_AB_i_dX*modelStruct.modelVar_cjobot)+(instanceStruct.instanceVar_LS_i*modelStruct.d_modelVar_cjosti_dX+instanceStruct.d_instanceVar_LS_i_dX*modelStruct.modelVar_cjosti))+(instanceStruct.instanceVar_LG_i*modelStruct.d_modelVar_cjogat_dX+instanceStruct.d_instanceVar_LG_i_dX*modelStruct.modelVar_cjogat))+modelStruct.d_modelVar_FJUNQ_i_dX*(((instanceStruct.instanceVar_AB_i*modelStruct.modelVar_cjobot)+(instanceStruct.instanceVar_LS_i*modelStruct.modelVar_cjosti))+(instanceStruct.instanceVar_LG_i*modelStruct.modelVar_cjogat)));
zfrac = (modelStruct.modelVar_FJUNQ_i*(((instanceStruct.instanceVar_AB_i*modelStruct.modelVar_cjobot)+(instanceStruct.instanceVar_LS_i*modelStruct.modelVar_cjosti))+(instanceStruct.instanceVar_LG_i*modelStruct.modelVar_cjogat)));
if (((instanceStruct.instanceVar_AB_i*modelStruct.modelVar_cjobot)<=zfrac))
{
instanceStruct.instanceVar_zflagbot = 0.0;
}
if (((instanceStruct.instanceVar_LS_i*modelStruct.modelVar_cjosti)<=zfrac))
{
instanceStruct.instanceVar_zflagsti = 0.0;
}
if (((instanceStruct.instanceVar_LG_i*modelStruct.modelVar_cjogat)<=zfrac))
{
instanceStruct.instanceVar_zflaggat = 0.0;
}
if ((!(((instanceStruct.instanceVar_AB_i==0.0)&&(instanceStruct.instanceVar_LS_i==0.0))&&(instanceStruct.instanceVar_LG_i==0.0))))
{
{
double value_log_0 = log(((0.5*modelStruct.modelVar_IMAX_i)/(instanceStruct.instanceVar_ISATFOR1+1.0e-21)));
double  deriv_log_0_d0 = (1.0/((0.5*modelStruct.modelVar_IMAX_i)/(instanceStruct.instanceVar_ISATFOR1+1.0e-21)));
instanceStruct.d_instanceVar_xhighf1_dX = deriv_log_0_d0*((((instanceStruct.instanceVar_ISATFOR1+1.0e-21)*0.5*modelStruct.d_modelVar_IMAX_i_dX-(0.5*modelStruct.modelVar_IMAX_i)*instanceStruct.d_instanceVar_ISATFOR1_dX)/(instanceStruct.instanceVar_ISATFOR1+1.0e-21)/(instanceStruct.instanceVar_ISATFOR1+1.0e-21)));
instanceStruct.instanceVar_xhighf1 = value_log_0;
}
{
double value_log_0 = log(((0.5*modelStruct.modelVar_IMAX_i)/(instanceStruct.instanceVar_ISATFOR2+1.0e-21)));
double  deriv_log_0_d0 = (1.0/((0.5*modelStruct.modelVar_IMAX_i)/(instanceStruct.instanceVar_ISATFOR2+1.0e-21)));
instanceStruct.d_instanceVar_xhighf2_dX = deriv_log_0_d0*((((instanceStruct.instanceVar_ISATFOR2+1.0e-21)*0.5*modelStruct.d_modelVar_IMAX_i_dX-(0.5*modelStruct.modelVar_IMAX_i)*instanceStruct.d_instanceVar_ISATFOR2_dX)/(instanceStruct.instanceVar_ISATFOR2+1.0e-21)/(instanceStruct.instanceVar_ISATFOR2+1.0e-21)));
instanceStruct.instanceVar_xhighf2 = value_log_0;
}
{
double value_fabs_0 = fabs(instanceStruct.instanceVar_ISATREV);
double value_log_1 = log(((0.5*modelStruct.modelVar_IMAX_i)/(value_fabs_0+1.0e-21)));
double  deriv_fabs_0_d0 = (((instanceStruct.instanceVar_ISATREV)>=0)?(+1.0):(-1.0));
double  deriv_log_1_d0 = (1.0/((0.5*modelStruct.modelVar_IMAX_i)/(value_fabs_0+1.0e-21)));
instanceStruct.d_instanceVar_xhighr_dX = deriv_log_1_d0*((((value_fabs_0+1.0e-21)*0.5*modelStruct.d_modelVar_IMAX_i_dX-(0.5*modelStruct.modelVar_IMAX_i)*deriv_fabs_0_d0*(instanceStruct.d_instanceVar_ISATREV_dX))/(value_fabs_0+1.0e-21)/(value_fabs_0+1.0e-21)));
instanceStruct.instanceVar_xhighr = value_log_1;
}
}
{
double value_min_0 = std::min(instanceStruct.instanceVar_xhighf1,static_cast<double>(2.3025850929940458e+02));
double  deriv_min_0_d0 = ((instanceStruct.instanceVar_xhighf1<=2.3025850929940458e+02)?1.0:0.0);
instanceStruct.d_instanceVar_xhighf1_dX = 0.0;
instanceStruct.instanceVar_xhighf1 = std::min(instanceStruct.instanceVar_xhighf1,static_cast<double>(2.3025850929940458e+02));
}
{
double value_exp_0 = exp(instanceStruct.instanceVar_xhighf1);
double  deriv_exp_0_d0 = value_exp_0;
instanceStruct.d_instanceVar_expxhf1_dX = deriv_exp_0_d0*(instanceStruct.d_instanceVar_xhighf1_dX);
instanceStruct.instanceVar_expxhf1 = value_exp_0;
}
{
double value_min_0 = std::min(instanceStruct.instanceVar_xhighf2,static_cast<double>(2.3025850929940458e+02));
double  deriv_min_0_d0 = ((instanceStruct.instanceVar_xhighf2<=2.3025850929940458e+02)?1.0:0.0);
instanceStruct.d_instanceVar_xhighf2_dX = 0.0;
instanceStruct.instanceVar_xhighf2 = std::min(instanceStruct.instanceVar_xhighf2,static_cast<double>(2.3025850929940458e+02));
}
{
double value_exp_0 = exp(instanceStruct.instanceVar_xhighf2);
double  deriv_exp_0_d0 = value_exp_0;
instanceStruct.d_instanceVar_expxhf2_dX = deriv_exp_0_d0*(instanceStruct.d_instanceVar_xhighf2_dX);
instanceStruct.instanceVar_expxhf2 = value_exp_0;
}
{
double value_min_0 = std::min(instanceStruct.instanceVar_xhighr,static_cast<double>(2.3025850929940458e+02));
double  deriv_min_0_d0 = ((instanceStruct.instanceVar_xhighr<=2.3025850929940458e+02)?1.0:0.0);
instanceStruct.d_instanceVar_xhighr_dX = 0.0;
instanceStruct.instanceVar_xhighr = std::min(instanceStruct.instanceVar_xhighr,static_cast<double>(2.3025850929940458e+02));
}
{
double value_exp_0 = exp(instanceStruct.instanceVar_xhighr);
double  deriv_exp_0_d0 = value_exp_0;
instanceStruct.d_instanceVar_expxhr_dX = deriv_exp_0_d0*(instanceStruct.d_instanceVar_xhighr_dX);
instanceStruct.instanceVar_expxhr = value_exp_0;
}
}
// End block JUNCAPexpressInit
}
// End block initial_instance
}



//-----------------------------------------------------------------------------
// Function      : evaluateInitialModel
// Purpose       : Evaluate the statements in the initial_model block
// Special Notes : specific for sensitivity use
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
void evaluateInitialModel(
modelSensStruct & modelStruct,
 double admsTemperature, double ADMSgmin_arg, const Instance & theInstance)
{
  double deltaEgat=0.0;
double d_deltaEgat_dX=0.0;
  double deltaEsti=0.0;
double d_deltaEsti_dX=0.0;
  double deltaEbot=0.0;
double d_deltaEbot_dX=0.0;
  double ubigat=0.0;
double d_ubigat_dX=0.0;
  double ubisti=0.0;
double d_ubisti_dX=0.0;
  double ubibot=0.0;
double d_ubibot_dX=0.0;
  double phigdgat=0.0;
double d_phigdgat_dX=0.0;
  double phigdsti=0.0;
double d_phigdsti_dX=0.0;
  double phigdbot=0.0;
double d_phigdbot_dX=0.0;
  double deltaphigd=0.0;
double d_deltaphigd_dX=0.0;
  double phigrgat=0.0;
double d_phigrgat_dX=0.0;
  double phigrsti=0.0;
double d_phigrsti_dX=0.0;
  double phigrbot=0.0;
double d_phigrbot_dX=0.0;
  double deltaphigr=0.0;
double d_deltaphigr_dX=0.0;
  double phitrinv=0.0;
double d_phitrinv_dX=0.0;
  double KBOL_over_QELE=0.0;
  double auxt=0.0;
double d_auxt_dX=0.0;
  double tkd=0.0;
double d_tkd_dX=0.0;
  double tkr=0.0;
double d_tkr_dX=0.0;
  double STFBBTGAT_i=0.0;
double d_STFBBTGAT_i_dX=0.0;
  double STFBBTSTI_i=0.0;
double d_STFBBTSTI_i_dX=0.0;
  double STFBBTBOT_i=0.0;
double d_STFBBTBOT_i_dX=0.0;
  double FBBTRGAT_i=0.0;
double d_FBBTRGAT_i_dX=0.0;
  double FBBTRSTI_i=0.0;
double d_FBBTRSTI_i_dX=0.0;
  double FBBTRBOT_i=0.0;
double d_FBBTRBOT_i_dX=0.0;
  double MEFFTATGAT_i=0.0;
double d_MEFFTATGAT_i_dX=0.0;
  double MEFFTATSTI_i=0.0;
double d_MEFFTATSTI_i_dX=0.0;
  double MEFFTATBOT_i=0.0;
double d_MEFFTATBOT_i_dX=0.0;
  double XJUNGAT_i=0.0;
double d_XJUNGAT_i_dX=0.0;
  double XJUNSTI_i=0.0;
double d_XJUNSTI_i_dX=0.0;
  double IDSATRGAT_i=0.0;
double d_IDSATRGAT_i_dX=0.0;
  double IDSATRSTI_i=0.0;
double d_IDSATRSTI_i_dX=0.0;
  double IDSATRBOT_i=0.0;
double d_IDSATRBOT_i_dX=0.0;
  double PHIGGAT_i=0.0;
double d_PHIGGAT_i_dX=0.0;
  double PHIGSTI_i=0.0;
double d_PHIGSTI_i_dX=0.0;
  double PHIGBOT_i=0.0;
double d_PHIGBOT_i_dX=0.0;
  double CJORGAT_i=0.0;
double d_CJORGAT_i_dX=0.0;
  double CJORSTI_i=0.0;
double d_CJORSTI_i_dX=0.0;
  double CJORBOT_i=0.0;
double d_CJORBOT_i_dX=0.0;
  double FREV_i=0.0;
double d_FREV_i_dX=0.0;
  double TRJ_i=0.0;
double d_TRJ_i_dX=0.0;
  double EPSSI=0.0;
//Begin block initial_model
{
EPSSI = (8.8541878176E-12*11.8);
d_TRJ_i_dX = ((modelStruct.modelPar_TRJ>(-2.5e2))?modelStruct.d_modelPar_TRJ_dX:0.0);
TRJ_i = ((modelStruct.modelPar_TRJ>(-2.5e2))?modelStruct.modelPar_TRJ:(-2.5e2));
modelStruct.d_modelVar_IMAX_i_dX = ((modelStruct.modelPar_IMAX>1.0e-12)?modelStruct.d_modelPar_IMAX_dX:0.0);
modelStruct.modelVar_IMAX_i = ((modelStruct.modelPar_IMAX>1.0e-12)?modelStruct.modelPar_IMAX:1.0e-12);
d_FREV_i_dX = ((modelStruct.modelPar_FREV>1.0e1)?((modelStruct.modelPar_FREV<1.0e10)?modelStruct.d_modelPar_FREV_dX:0.0):0.0);
FREV_i = ((modelStruct.modelPar_FREV>1.0e1)?((modelStruct.modelPar_FREV<1.0e10)?modelStruct.modelPar_FREV:1.0e10):1.0e1);
d_CJORBOT_i_dX = ((modelStruct.modelPar_CJORBOT>1.0e-12)?modelStruct.d_modelPar_CJORBOT_dX:0.0);
CJORBOT_i = ((modelStruct.modelPar_CJORBOT>1.0e-12)?modelStruct.modelPar_CJORBOT:1.0e-12);
d_CJORSTI_i_dX = ((modelStruct.modelPar_CJORSTI>1.0e-18)?modelStruct.d_modelPar_CJORSTI_dX:0.0);
CJORSTI_i = ((modelStruct.modelPar_CJORSTI>1.0e-18)?modelStruct.modelPar_CJORSTI:1.0e-18);
d_CJORGAT_i_dX = ((modelStruct.modelPar_CJORGAT>1.0e-18)?modelStruct.d_modelPar_CJORGAT_dX:0.0);
CJORGAT_i = ((modelStruct.modelPar_CJORGAT>1.0e-18)?modelStruct.modelPar_CJORGAT:1.0e-18);
modelStruct.d_modelVar_VBIRBOT_i_dX = ((modelStruct.modelPar_VBIRBOT>5.0e-2)?modelStruct.d_modelPar_VBIRBOT_dX:0.0);
modelStruct.modelVar_VBIRBOT_i = ((modelStruct.modelPar_VBIRBOT>5.0e-2)?modelStruct.modelPar_VBIRBOT:5.0e-2);
modelStruct.d_modelVar_VBIRSTI_i_dX = ((modelStruct.modelPar_VBIRSTI>5.0e-2)?modelStruct.d_modelPar_VBIRSTI_dX:0.0);
modelStruct.modelVar_VBIRSTI_i = ((modelStruct.modelPar_VBIRSTI>5.0e-2)?modelStruct.modelPar_VBIRSTI:5.0e-2);
modelStruct.d_modelVar_VBIRGAT_i_dX = ((modelStruct.modelPar_VBIRGAT>5.0e-2)?modelStruct.d_modelPar_VBIRGAT_dX:0.0);
modelStruct.modelVar_VBIRGAT_i = ((modelStruct.modelPar_VBIRGAT>5.0e-2)?modelStruct.modelPar_VBIRGAT:5.0e-2);
modelStruct.d_modelVar_PBOT_i_dX = ((modelStruct.modelPar_PBOT>5.0e-2)?((modelStruct.modelPar_PBOT<0.95)?modelStruct.d_modelPar_PBOT_dX:0.0):0.0);
modelStruct.modelVar_PBOT_i = ((modelStruct.modelPar_PBOT>5.0e-2)?((modelStruct.modelPar_PBOT<0.95)?modelStruct.modelPar_PBOT:0.95):5.0e-2);
modelStruct.d_modelVar_PSTI_i_dX = ((modelStruct.modelPar_PSTI>5.0e-2)?((modelStruct.modelPar_PSTI<0.95)?modelStruct.d_modelPar_PSTI_dX:0.0):0.0);
modelStruct.modelVar_PSTI_i = ((modelStruct.modelPar_PSTI>5.0e-2)?((modelStruct.modelPar_PSTI<0.95)?modelStruct.modelPar_PSTI:0.95):5.0e-2);
modelStruct.d_modelVar_PGAT_i_dX = ((modelStruct.modelPar_PGAT>5.0e-2)?((modelStruct.modelPar_PGAT<0.95)?modelStruct.d_modelPar_PGAT_dX:0.0):0.0);
modelStruct.modelVar_PGAT_i = ((modelStruct.modelPar_PGAT>5.0e-2)?((modelStruct.modelPar_PGAT<0.95)?modelStruct.modelPar_PGAT:0.95):5.0e-2);
d_PHIGBOT_i_dX = modelStruct.d_modelPar_PHIGBOT_dX;
PHIGBOT_i = modelStruct.modelPar_PHIGBOT;
d_PHIGSTI_i_dX = modelStruct.d_modelPar_PHIGSTI_dX;
PHIGSTI_i = modelStruct.modelPar_PHIGSTI;
d_PHIGGAT_i_dX = modelStruct.d_modelPar_PHIGGAT_dX;
PHIGGAT_i = modelStruct.modelPar_PHIGGAT;
d_IDSATRBOT_i_dX = ((modelStruct.modelPar_IDSATRBOT>0.0)?modelStruct.d_modelPar_IDSATRBOT_dX:0.0);
IDSATRBOT_i = ((modelStruct.modelPar_IDSATRBOT>0.0)?modelStruct.modelPar_IDSATRBOT:0.0);
d_IDSATRSTI_i_dX = ((modelStruct.modelPar_IDSATRSTI>0.0)?modelStruct.d_modelPar_IDSATRSTI_dX:0.0);
IDSATRSTI_i = ((modelStruct.modelPar_IDSATRSTI>0.0)?modelStruct.modelPar_IDSATRSTI:0.0);
d_IDSATRGAT_i_dX = ((modelStruct.modelPar_IDSATRGAT>0.0)?modelStruct.d_modelPar_IDSATRGAT_dX:0.0);
IDSATRGAT_i = ((modelStruct.modelPar_IDSATRGAT>0.0)?modelStruct.modelPar_IDSATRGAT:0.0);
modelStruct.d_modelVar_CSRHBOT_i_dX = ((modelStruct.modelPar_CSRHBOT>0.0)?modelStruct.d_modelPar_CSRHBOT_dX:0.0);
modelStruct.modelVar_CSRHBOT_i = ((modelStruct.modelPar_CSRHBOT>0.0)?modelStruct.modelPar_CSRHBOT:0.0);
modelStruct.d_modelVar_CSRHSTI_i_dX = ((modelStruct.modelPar_CSRHSTI>0.0)?modelStruct.d_modelPar_CSRHSTI_dX:0.0);
modelStruct.modelVar_CSRHSTI_i = ((modelStruct.modelPar_CSRHSTI>0.0)?modelStruct.modelPar_CSRHSTI:0.0);
modelStruct.d_modelVar_CSRHGAT_i_dX = ((modelStruct.modelPar_CSRHGAT>0.0)?modelStruct.d_modelPar_CSRHGAT_dX:0.0);
modelStruct.modelVar_CSRHGAT_i = ((modelStruct.modelPar_CSRHGAT>0.0)?modelStruct.modelPar_CSRHGAT:0.0);
d_XJUNSTI_i_dX = ((modelStruct.modelPar_XJUNSTI>1.0e-9)?modelStruct.d_modelPar_XJUNSTI_dX:0.0);
XJUNSTI_i = ((modelStruct.modelPar_XJUNSTI>1.0e-9)?modelStruct.modelPar_XJUNSTI:1.0e-9);
d_XJUNGAT_i_dX = ((modelStruct.modelPar_XJUNGAT>1.0e-9)?modelStruct.d_modelPar_XJUNGAT_dX:0.0);
XJUNGAT_i = ((modelStruct.modelPar_XJUNGAT>1.0e-9)?modelStruct.modelPar_XJUNGAT:1.0e-9);
modelStruct.d_modelVar_CTATBOT_i_dX = ((modelStruct.modelPar_CTATBOT>0.0)?modelStruct.d_modelPar_CTATBOT_dX:0.0);
modelStruct.modelVar_CTATBOT_i = ((modelStruct.modelPar_CTATBOT>0.0)?modelStruct.modelPar_CTATBOT:0.0);
modelStruct.d_modelVar_CTATSTI_i_dX = ((modelStruct.modelPar_CTATSTI>0.0)?modelStruct.d_modelPar_CTATSTI_dX:0.0);
modelStruct.modelVar_CTATSTI_i = ((modelStruct.modelPar_CTATSTI>0.0)?modelStruct.modelPar_CTATSTI:0.0);
modelStruct.d_modelVar_CTATGAT_i_dX = ((modelStruct.modelPar_CTATGAT>0.0)?modelStruct.d_modelPar_CTATGAT_dX:0.0);
modelStruct.modelVar_CTATGAT_i = ((modelStruct.modelPar_CTATGAT>0.0)?modelStruct.modelPar_CTATGAT:0.0);
d_MEFFTATBOT_i_dX = ((modelStruct.modelPar_MEFFTATBOT>1.0e-2)?modelStruct.d_modelPar_MEFFTATBOT_dX:0.0);
MEFFTATBOT_i = ((modelStruct.modelPar_MEFFTATBOT>1.0e-2)?modelStruct.modelPar_MEFFTATBOT:1.0e-2);
d_MEFFTATSTI_i_dX = ((modelStruct.modelPar_MEFFTATSTI>1.0e-2)?modelStruct.d_modelPar_MEFFTATSTI_dX:0.0);
MEFFTATSTI_i = ((modelStruct.modelPar_MEFFTATSTI>1.0e-2)?modelStruct.modelPar_MEFFTATSTI:1.0e-2);
d_MEFFTATGAT_i_dX = ((modelStruct.modelPar_MEFFTATGAT>1.0e-2)?modelStruct.d_modelPar_MEFFTATGAT_dX:0.0);
MEFFTATGAT_i = ((modelStruct.modelPar_MEFFTATGAT>1.0e-2)?modelStruct.modelPar_MEFFTATGAT:1.0e-2);
modelStruct.d_modelVar_CBBTBOT_i_dX = ((modelStruct.modelPar_CBBTBOT>0.0)?modelStruct.d_modelPar_CBBTBOT_dX:0.0);
modelStruct.modelVar_CBBTBOT_i = ((modelStruct.modelPar_CBBTBOT>0.0)?modelStruct.modelPar_CBBTBOT:0.0);
modelStruct.d_modelVar_CBBTSTI_i_dX = ((modelStruct.modelPar_CBBTSTI>0.0)?modelStruct.d_modelPar_CBBTSTI_dX:0.0);
modelStruct.modelVar_CBBTSTI_i = ((modelStruct.modelPar_CBBTSTI>0.0)?modelStruct.modelPar_CBBTSTI:0.0);
modelStruct.d_modelVar_CBBTGAT_i_dX = ((modelStruct.modelPar_CBBTGAT>0.0)?modelStruct.d_modelPar_CBBTGAT_dX:0.0);
modelStruct.modelVar_CBBTGAT_i = ((modelStruct.modelPar_CBBTGAT>0.0)?modelStruct.modelPar_CBBTGAT:0.0);
d_FBBTRBOT_i_dX = modelStruct.d_modelPar_FBBTRBOT_dX;
FBBTRBOT_i = modelStruct.modelPar_FBBTRBOT;
d_FBBTRSTI_i_dX = modelStruct.d_modelPar_FBBTRSTI_dX;
FBBTRSTI_i = modelStruct.modelPar_FBBTRSTI;
d_FBBTRGAT_i_dX = modelStruct.d_modelPar_FBBTRGAT_dX;
FBBTRGAT_i = modelStruct.modelPar_FBBTRGAT;
d_STFBBTBOT_i_dX = modelStruct.d_modelPar_STFBBTBOT_dX;
STFBBTBOT_i = modelStruct.modelPar_STFBBTBOT;
d_STFBBTSTI_i_dX = modelStruct.d_modelPar_STFBBTSTI_dX;
STFBBTSTI_i = modelStruct.modelPar_STFBBTSTI;
d_STFBBTGAT_i_dX = modelStruct.d_modelPar_STFBBTGAT_dX;
STFBBTGAT_i = modelStruct.modelPar_STFBBTGAT;
modelStruct.d_modelVar_VBRBOT_i_dX = ((modelStruct.modelPar_VBRBOT>0.1)?modelStruct.d_modelPar_VBRBOT_dX:0.0);
modelStruct.modelVar_VBRBOT_i = ((modelStruct.modelPar_VBRBOT>0.1)?modelStruct.modelPar_VBRBOT:0.1);
modelStruct.d_modelVar_VBRSTI_i_dX = ((modelStruct.modelPar_VBRSTI>0.1)?modelStruct.d_modelPar_VBRSTI_dX:0.0);
modelStruct.modelVar_VBRSTI_i = ((modelStruct.modelPar_VBRSTI>0.1)?modelStruct.modelPar_VBRSTI:0.1);
modelStruct.d_modelVar_VBRGAT_i_dX = ((modelStruct.modelPar_VBRGAT>0.1)?modelStruct.d_modelPar_VBRGAT_dX:0.0);
modelStruct.modelVar_VBRGAT_i = ((modelStruct.modelPar_VBRGAT>0.1)?modelStruct.modelPar_VBRGAT:0.1);
modelStruct.d_modelVar_PBRBOT_i_dX = ((modelStruct.modelPar_PBRBOT>0.1)?modelStruct.d_modelPar_PBRBOT_dX:0.0);
modelStruct.modelVar_PBRBOT_i = ((modelStruct.modelPar_PBRBOT>0.1)?modelStruct.modelPar_PBRBOT:0.1);
modelStruct.d_modelVar_PBRSTI_i_dX = ((modelStruct.modelPar_PBRSTI>0.1)?modelStruct.d_modelPar_PBRSTI_dX:0.0);
modelStruct.modelVar_PBRSTI_i = ((modelStruct.modelPar_PBRSTI>0.1)?modelStruct.modelPar_PBRSTI:0.1);
modelStruct.d_modelVar_PBRGAT_i_dX = ((modelStruct.modelPar_PBRGAT>0.1)?modelStruct.d_modelPar_PBRGAT_dX:0.0);
modelStruct.modelVar_PBRGAT_i = ((modelStruct.modelPar_PBRGAT>0.1)?modelStruct.modelPar_PBRGAT:0.1);
modelStruct.modelVar_SWJUNEXP_i = 0.0;
if ((modelStruct.modelPar_SWJUNEXP>0.5))
{
modelStruct.modelVar_SWJUNEXP_i = 1.0;
}
else
{
modelStruct.modelVar_SWJUNEXP_i = 0.0;
}
modelStruct.d_modelVar_VJUNREF_i_dX = ((modelStruct.modelPar_VJUNREF>0.5)?modelStruct.d_modelPar_VJUNREF_dX:0.0);
modelStruct.modelVar_VJUNREF_i = ((modelStruct.modelPar_VJUNREF>0.5)?modelStruct.modelPar_VJUNREF:0.5);
modelStruct.d_modelVar_FJUNQ_i_dX = ((modelStruct.modelPar_FJUNQ>0.0)?modelStruct.d_modelPar_FJUNQ_dX:0.0);
modelStruct.modelVar_FJUNQ_i = ((modelStruct.modelPar_FJUNQ>0.0)?modelStruct.modelPar_FJUNQ:0.0);
d_tkr_dX = d_TRJ_i_dX;
tkr = (273.15+TRJ_i);
{
double value_max_0 = std::max((admsTemperature+modelStruct.modelPar_DTA),(273.15+(-2.5e2)));
double  deriv_max_0_d0 = (((admsTemperature+modelStruct.modelPar_DTA)>=(273.15+(-2.5e2)))?1.0:0.0);
d_tkd_dX = (deriv_max_0_d0*(modelStruct.d_modelPar_DTA_dX));
tkd = value_max_0;
}
d_auxt_dX = ((tkr*d_tkd_dX-tkd*d_tkr_dX)/tkr/tkr);
auxt = (tkd/tkr);
KBOL_over_QELE = (1.3806505E-23/1.6021918E-19);
modelStruct.d_modelVar_phitr_dX = KBOL_over_QELE*d_tkr_dX;
modelStruct.modelVar_phitr = (KBOL_over_QELE*tkr);
d_phitrinv_dX = (-modelStruct.d_modelVar_phitr_dX/modelStruct.modelVar_phitr/modelStruct.modelVar_phitr);
phitrinv = (1.0/modelStruct.modelVar_phitr);
modelStruct.d_modelVar_phitd_dX = KBOL_over_QELE*d_tkd_dX;
modelStruct.modelVar_phitd = (KBOL_over_QELE*tkd);
modelStruct.d_modelVar_phitdinv_dX = (-modelStruct.d_modelVar_phitd_dX/modelStruct.modelVar_phitd/modelStruct.modelVar_phitd);
modelStruct.modelVar_phitdinv = (1.0/modelStruct.modelVar_phitd);
d_deltaphigr_dX = (((1108.0+tkr)*(-((7.02e-4*tkr)*d_tkr_dX+7.02e-4*d_tkr_dX*tkr))-(-((7.02e-4*tkr)*tkr))*d_tkr_dX)/(1108.0+tkr)/(1108.0+tkr));
deltaphigr = ((-((7.02e-4*tkr)*tkr))/(1108.0+tkr));
d_phigrbot_dX = (d_PHIGBOT_i_dX+d_deltaphigr_dX);
phigrbot = (PHIGBOT_i+deltaphigr);
d_phigrsti_dX = (d_PHIGSTI_i_dX+d_deltaphigr_dX);
phigrsti = (PHIGSTI_i+deltaphigr);
d_phigrgat_dX = (d_PHIGGAT_i_dX+d_deltaphigr_dX);
phigrgat = (PHIGGAT_i+deltaphigr);
d_deltaphigd_dX = (((1108.0+tkd)*(-((7.02e-4*tkd)*d_tkd_dX+7.02e-4*d_tkd_dX*tkd))-(-((7.02e-4*tkd)*tkd))*d_tkd_dX)/(1108.0+tkd)/(1108.0+tkd));
deltaphigd = ((-((7.02e-4*tkd)*tkd))/(1108.0+tkd));
d_phigdbot_dX = (d_PHIGBOT_i_dX+d_deltaphigd_dX);
phigdbot = (PHIGBOT_i+deltaphigd);
d_phigdsti_dX = (d_PHIGSTI_i_dX+d_deltaphigd_dX);
phigdsti = (PHIGSTI_i+deltaphigd);
d_phigdgat_dX = (d_PHIGGAT_i_dX+d_deltaphigd_dX);
phigdgat = (PHIGGAT_i+deltaphigd);
{
double value_pow_0 = pow(auxt,1.5);
double value_exp_1 = exp((0.5*((phigrbot*phitrinv)-(phigdbot*modelStruct.modelVar_phitdinv))));
double  deriv_pow_0_d0 = ((auxt == 0.0)?0.0:(value_pow_0*1.5/auxt));
double  deriv_exp_1_d0 = value_exp_1;
modelStruct.d_modelVar_ftdbot_dX = (value_pow_0*deriv_exp_1_d0*(0.5*((phigrbot*d_phitrinv_dX+d_phigrbot_dX*phitrinv)-(phigdbot*modelStruct.d_modelVar_phitdinv_dX+d_phigdbot_dX*modelStruct.modelVar_phitdinv)))+(deriv_pow_0_d0*(d_auxt_dX))*value_exp_1);
modelStruct.modelVar_ftdbot = (value_pow_0*value_exp_1);
}
{
double value_pow_0 = pow(auxt,1.5);
double value_exp_1 = exp((0.5*((phigrsti*phitrinv)-(phigdsti*modelStruct.modelVar_phitdinv))));
double  deriv_pow_0_d0 = ((auxt == 0.0)?0.0:(value_pow_0*1.5/auxt));
double  deriv_exp_1_d0 = value_exp_1;
modelStruct.d_modelVar_ftdsti_dX = (value_pow_0*deriv_exp_1_d0*(0.5*((phigrsti*d_phitrinv_dX+d_phigrsti_dX*phitrinv)-(phigdsti*modelStruct.d_modelVar_phitdinv_dX+d_phigdsti_dX*modelStruct.modelVar_phitdinv)))+(deriv_pow_0_d0*(d_auxt_dX))*value_exp_1);
modelStruct.modelVar_ftdsti = (value_pow_0*value_exp_1);
}
{
double value_pow_0 = pow(auxt,1.5);
double value_exp_1 = exp((0.5*((phigrgat*phitrinv)-(phigdgat*modelStruct.modelVar_phitdinv))));
double  deriv_pow_0_d0 = ((auxt == 0.0)?0.0:(value_pow_0*1.5/auxt));
double  deriv_exp_1_d0 = value_exp_1;
modelStruct.d_modelVar_ftdgat_dX = (value_pow_0*deriv_exp_1_d0*(0.5*((phigrgat*d_phitrinv_dX+d_phigrgat_dX*phitrinv)-(phigdgat*modelStruct.d_modelVar_phitdinv_dX+d_phigdgat_dX*modelStruct.modelVar_phitdinv)))+(deriv_pow_0_d0*(d_auxt_dX))*value_exp_1);
modelStruct.modelVar_ftdgat = (value_pow_0*value_exp_1);
}
modelStruct.d_modelVar_idsatbot_dX = ((IDSATRBOT_i*modelStruct.modelVar_ftdbot)*modelStruct.d_modelVar_ftdbot_dX+(IDSATRBOT_i*modelStruct.d_modelVar_ftdbot_dX+d_IDSATRBOT_i_dX*modelStruct.modelVar_ftdbot)*modelStruct.modelVar_ftdbot);
modelStruct.modelVar_idsatbot = ((IDSATRBOT_i*modelStruct.modelVar_ftdbot)*modelStruct.modelVar_ftdbot);
modelStruct.d_modelVar_idsatsti_dX = ((IDSATRSTI_i*modelStruct.modelVar_ftdsti)*modelStruct.d_modelVar_ftdsti_dX+(IDSATRSTI_i*modelStruct.d_modelVar_ftdsti_dX+d_IDSATRSTI_i_dX*modelStruct.modelVar_ftdsti)*modelStruct.modelVar_ftdsti);
modelStruct.modelVar_idsatsti = ((IDSATRSTI_i*modelStruct.modelVar_ftdsti)*modelStruct.modelVar_ftdsti);
modelStruct.d_modelVar_idsatgat_dX = ((IDSATRGAT_i*modelStruct.modelVar_ftdgat)*modelStruct.d_modelVar_ftdgat_dX+(IDSATRGAT_i*modelStruct.d_modelVar_ftdgat_dX+d_IDSATRGAT_i_dX*modelStruct.modelVar_ftdgat)*modelStruct.modelVar_ftdgat);
modelStruct.modelVar_idsatgat = ((IDSATRGAT_i*modelStruct.modelVar_ftdgat)*modelStruct.modelVar_ftdgat);
{
double value_log_0 = log(modelStruct.modelVar_ftdbot);
double  deriv_log_0_d0 = (1.0/modelStruct.modelVar_ftdbot);
d_ubibot_dX = ((modelStruct.modelVar_VBIRBOT_i*d_auxt_dX+modelStruct.d_modelVar_VBIRBOT_i_dX*auxt)-((2.0*modelStruct.modelVar_phitd)*deriv_log_0_d0*(modelStruct.d_modelVar_ftdbot_dX)+2.0*modelStruct.d_modelVar_phitd_dX*value_log_0));
ubibot = ((modelStruct.modelVar_VBIRBOT_i*auxt)-((2.0*modelStruct.modelVar_phitd)*value_log_0));
}
{
double value_log_0 = log(modelStruct.modelVar_ftdsti);
double  deriv_log_0_d0 = (1.0/modelStruct.modelVar_ftdsti);
d_ubisti_dX = ((modelStruct.modelVar_VBIRSTI_i*d_auxt_dX+modelStruct.d_modelVar_VBIRSTI_i_dX*auxt)-((2.0*modelStruct.modelVar_phitd)*deriv_log_0_d0*(modelStruct.d_modelVar_ftdsti_dX)+2.0*modelStruct.d_modelVar_phitd_dX*value_log_0));
ubisti = ((modelStruct.modelVar_VBIRSTI_i*auxt)-((2.0*modelStruct.modelVar_phitd)*value_log_0));
}
{
double value_log_0 = log(modelStruct.modelVar_ftdgat);
double  deriv_log_0_d0 = (1.0/modelStruct.modelVar_ftdgat);
d_ubigat_dX = ((modelStruct.modelVar_VBIRGAT_i*d_auxt_dX+modelStruct.d_modelVar_VBIRGAT_i_dX*auxt)-((2.0*modelStruct.modelVar_phitd)*deriv_log_0_d0*(modelStruct.d_modelVar_ftdgat_dX)+2.0*modelStruct.d_modelVar_phitd_dX*value_log_0));
ubigat = ((modelStruct.modelVar_VBIRGAT_i*auxt)-((2.0*modelStruct.modelVar_phitd)*value_log_0));
}
{
double value_exp_0 = exp(((5.0e-2-ubibot)*modelStruct.modelVar_phitdinv));
double value_log_1 = log((1+value_exp_0));
double  deriv_exp_0_d0 = value_exp_0;
double  deriv_log_1_d0 = (1.0/(1+value_exp_0));
modelStruct.d_modelVar_vbibot_dX = (d_ubibot_dX+(modelStruct.modelVar_phitd*deriv_log_1_d0*(deriv_exp_0_d0*(((5.0e-2-ubibot)*modelStruct.d_modelVar_phitdinv_dX+(-d_ubibot_dX)*modelStruct.modelVar_phitdinv)))+modelStruct.d_modelVar_phitd_dX*value_log_1));
modelStruct.modelVar_vbibot = (ubibot+(modelStruct.modelVar_phitd*value_log_1));
}
{
double value_exp_0 = exp(((5.0e-2-ubisti)*modelStruct.modelVar_phitdinv));
double value_log_1 = log((1+value_exp_0));
double  deriv_exp_0_d0 = value_exp_0;
double  deriv_log_1_d0 = (1.0/(1+value_exp_0));
modelStruct.d_modelVar_vbisti_dX = (d_ubisti_dX+(modelStruct.modelVar_phitd*deriv_log_1_d0*(deriv_exp_0_d0*(((5.0e-2-ubisti)*modelStruct.d_modelVar_phitdinv_dX+(-d_ubisti_dX)*modelStruct.modelVar_phitdinv)))+modelStruct.d_modelVar_phitd_dX*value_log_1));
modelStruct.modelVar_vbisti = (ubisti+(modelStruct.modelVar_phitd*value_log_1));
}
{
double value_exp_0 = exp(((5.0e-2-ubigat)*modelStruct.modelVar_phitdinv));
double value_log_1 = log((1+value_exp_0));
double  deriv_exp_0_d0 = value_exp_0;
double  deriv_log_1_d0 = (1.0/(1+value_exp_0));
modelStruct.d_modelVar_vbigat_dX = (d_ubigat_dX+(modelStruct.modelVar_phitd*deriv_log_1_d0*(deriv_exp_0_d0*(((5.0e-2-ubigat)*modelStruct.d_modelVar_phitdinv_dX+(-d_ubigat_dX)*modelStruct.modelVar_phitdinv)))+modelStruct.d_modelVar_phitd_dX*value_log_1));
modelStruct.modelVar_vbigat = (ubigat+(modelStruct.modelVar_phitd*value_log_1));
}
modelStruct.d_modelVar_vbiinvbot_dX = (-modelStruct.d_modelVar_vbibot_dX/modelStruct.modelVar_vbibot/modelStruct.modelVar_vbibot);
modelStruct.modelVar_vbiinvbot = (1.0/modelStruct.modelVar_vbibot);
modelStruct.d_modelVar_vbiinvsti_dX = (-modelStruct.d_modelVar_vbisti_dX/modelStruct.modelVar_vbisti/modelStruct.modelVar_vbisti);
modelStruct.modelVar_vbiinvsti = (1.0/modelStruct.modelVar_vbisti);
modelStruct.d_modelVar_vbiinvgat_dX = (-modelStruct.d_modelVar_vbigat_dX/modelStruct.modelVar_vbigat/modelStruct.modelVar_vbigat);
modelStruct.modelVar_vbiinvgat = (1.0/modelStruct.modelVar_vbigat);
modelStruct.d_modelVar_one_minus_PBOT_dX = (-modelStruct.d_modelVar_PBOT_i_dX);
modelStruct.modelVar_one_minus_PBOT = (1.0-modelStruct.modelVar_PBOT_i);
modelStruct.d_modelVar_one_minus_PSTI_dX = (-modelStruct.d_modelVar_PSTI_i_dX);
modelStruct.modelVar_one_minus_PSTI = (1.0-modelStruct.modelVar_PSTI_i);
modelStruct.d_modelVar_one_minus_PGAT_dX = (-modelStruct.d_modelVar_PGAT_i_dX);
modelStruct.modelVar_one_minus_PGAT = (1.0-modelStruct.modelVar_PGAT_i);
modelStruct.d_modelVar_one_over_one_minus_PBOT_dX = (-modelStruct.d_modelVar_one_minus_PBOT_dX/modelStruct.modelVar_one_minus_PBOT/modelStruct.modelVar_one_minus_PBOT);
modelStruct.modelVar_one_over_one_minus_PBOT = (1.0/modelStruct.modelVar_one_minus_PBOT);
modelStruct.d_modelVar_one_over_one_minus_PSTI_dX = (-modelStruct.d_modelVar_one_minus_PSTI_dX/modelStruct.modelVar_one_minus_PSTI/modelStruct.modelVar_one_minus_PSTI);
modelStruct.modelVar_one_over_one_minus_PSTI = (1.0/modelStruct.modelVar_one_minus_PSTI);
modelStruct.d_modelVar_one_over_one_minus_PGAT_dX = (-modelStruct.d_modelVar_one_minus_PGAT_dX/modelStruct.modelVar_one_minus_PGAT/modelStruct.modelVar_one_minus_PGAT);
modelStruct.modelVar_one_over_one_minus_PGAT = (1.0/modelStruct.modelVar_one_minus_PGAT);
{
double value_pow_0 = pow((modelStruct.modelVar_VBIRBOT_i*modelStruct.modelVar_vbiinvbot),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = (((modelStruct.modelVar_VBIRBOT_i*modelStruct.modelVar_vbiinvbot) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/(modelStruct.modelVar_VBIRBOT_i*modelStruct.modelVar_vbiinvbot)));
double  deriv_pow_0_d1 = ((modelStruct.modelVar_VBIRBOT_i*modelStruct.modelVar_vbiinvbot) == 0.0)?0.0:(log((modelStruct.modelVar_VBIRBOT_i*modelStruct.modelVar_vbiinvbot))*value_pow_0);
modelStruct.d_modelVar_cjobot_dX = (CJORBOT_i*((deriv_pow_0_d0*((modelStruct.modelVar_VBIRBOT_i*modelStruct.d_modelVar_vbiinvbot_dX+modelStruct.d_modelVar_VBIRBOT_i_dX*modelStruct.modelVar_vbiinvbot)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)))+d_CJORBOT_i_dX*value_pow_0);
modelStruct.modelVar_cjobot = (CJORBOT_i*value_pow_0);
}
{
double value_pow_0 = pow((modelStruct.modelVar_VBIRSTI_i*modelStruct.modelVar_vbiinvsti),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = (((modelStruct.modelVar_VBIRSTI_i*modelStruct.modelVar_vbiinvsti) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/(modelStruct.modelVar_VBIRSTI_i*modelStruct.modelVar_vbiinvsti)));
double  deriv_pow_0_d1 = ((modelStruct.modelVar_VBIRSTI_i*modelStruct.modelVar_vbiinvsti) == 0.0)?0.0:(log((modelStruct.modelVar_VBIRSTI_i*modelStruct.modelVar_vbiinvsti))*value_pow_0);
modelStruct.d_modelVar_cjosti_dX = (CJORSTI_i*((deriv_pow_0_d0*((modelStruct.modelVar_VBIRSTI_i*modelStruct.d_modelVar_vbiinvsti_dX+modelStruct.d_modelVar_VBIRSTI_i_dX*modelStruct.modelVar_vbiinvsti)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)))+d_CJORSTI_i_dX*value_pow_0);
modelStruct.modelVar_cjosti = (CJORSTI_i*value_pow_0);
}
{
double value_pow_0 = pow((modelStruct.modelVar_VBIRGAT_i*modelStruct.modelVar_vbiinvgat),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = (((modelStruct.modelVar_VBIRGAT_i*modelStruct.modelVar_vbiinvgat) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/(modelStruct.modelVar_VBIRGAT_i*modelStruct.modelVar_vbiinvgat)));
double  deriv_pow_0_d1 = ((modelStruct.modelVar_VBIRGAT_i*modelStruct.modelVar_vbiinvgat) == 0.0)?0.0:(log((modelStruct.modelVar_VBIRGAT_i*modelStruct.modelVar_vbiinvgat))*value_pow_0);
modelStruct.d_modelVar_cjogat_dX = (CJORGAT_i*((deriv_pow_0_d0*((modelStruct.modelVar_VBIRGAT_i*modelStruct.d_modelVar_vbiinvgat_dX+modelStruct.d_modelVar_VBIRGAT_i_dX*modelStruct.modelVar_vbiinvgat)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)))+d_CJORGAT_i_dX*value_pow_0);
modelStruct.modelVar_cjogat = (CJORGAT_i*value_pow_0);
}
modelStruct.d_modelVar_qprefbot_dX = ((modelStruct.modelVar_cjobot*modelStruct.modelVar_vbibot)*modelStruct.d_modelVar_one_over_one_minus_PBOT_dX+(modelStruct.modelVar_cjobot*modelStruct.d_modelVar_vbibot_dX+modelStruct.d_modelVar_cjobot_dX*modelStruct.modelVar_vbibot)*modelStruct.modelVar_one_over_one_minus_PBOT);
modelStruct.modelVar_qprefbot = ((modelStruct.modelVar_cjobot*modelStruct.modelVar_vbibot)*modelStruct.modelVar_one_over_one_minus_PBOT);
modelStruct.d_modelVar_qprefsti_dX = ((modelStruct.modelVar_cjosti*modelStruct.modelVar_vbisti)*modelStruct.d_modelVar_one_over_one_minus_PSTI_dX+(modelStruct.modelVar_cjosti*modelStruct.d_modelVar_vbisti_dX+modelStruct.d_modelVar_cjosti_dX*modelStruct.modelVar_vbisti)*modelStruct.modelVar_one_over_one_minus_PSTI);
modelStruct.modelVar_qprefsti = ((modelStruct.modelVar_cjosti*modelStruct.modelVar_vbisti)*modelStruct.modelVar_one_over_one_minus_PSTI);
modelStruct.d_modelVar_qprefgat_dX = ((modelStruct.modelVar_cjogat*modelStruct.modelVar_vbigat)*modelStruct.d_modelVar_one_over_one_minus_PGAT_dX+(modelStruct.modelVar_cjogat*modelStruct.d_modelVar_vbigat_dX+modelStruct.d_modelVar_cjogat_dX*modelStruct.modelVar_vbigat)*modelStruct.modelVar_one_over_one_minus_PGAT);
modelStruct.modelVar_qprefgat = ((modelStruct.modelVar_cjogat*modelStruct.modelVar_vbigat)*modelStruct.modelVar_one_over_one_minus_PGAT);
modelStruct.d_modelVar_qpref2bot_dX = 2.0*modelStruct.d_modelVar_cjobot_dX;
modelStruct.modelVar_qpref2bot = (2.0*modelStruct.modelVar_cjobot);
modelStruct.d_modelVar_qpref2sti_dX = 2.0*modelStruct.d_modelVar_cjosti_dX;
modelStruct.modelVar_qpref2sti = (2.0*modelStruct.modelVar_cjosti);
modelStruct.d_modelVar_qpref2gat_dX = 2.0*modelStruct.d_modelVar_cjogat_dX;
modelStruct.modelVar_qpref2gat = (2.0*modelStruct.modelVar_cjogat);
modelStruct.d_modelVar_wdepnulrbot_dX = (-EPSSI*d_CJORBOT_i_dX/CJORBOT_i/CJORBOT_i);
modelStruct.modelVar_wdepnulrbot = (EPSSI/CJORBOT_i);
modelStruct.d_modelVar_wdepnulrsti_dX = ((CJORSTI_i*d_XJUNSTI_i_dX*EPSSI-(XJUNSTI_i*EPSSI)*d_CJORSTI_i_dX)/CJORSTI_i/CJORSTI_i);
modelStruct.modelVar_wdepnulrsti = ((XJUNSTI_i*EPSSI)/CJORSTI_i);
modelStruct.d_modelVar_wdepnulrgat_dX = ((CJORGAT_i*d_XJUNGAT_i_dX*EPSSI-(XJUNGAT_i*EPSSI)*d_CJORGAT_i_dX)/CJORGAT_i/CJORGAT_i);
modelStruct.modelVar_wdepnulrgat = ((XJUNGAT_i*EPSSI)/CJORGAT_i);
modelStruct.d_modelVar_wdepnulrinvbot_dX = (-modelStruct.d_modelVar_wdepnulrbot_dX/modelStruct.modelVar_wdepnulrbot/modelStruct.modelVar_wdepnulrbot);
modelStruct.modelVar_wdepnulrinvbot = (1.0/modelStruct.modelVar_wdepnulrbot);
modelStruct.d_modelVar_wdepnulrinvsti_dX = (-modelStruct.d_modelVar_wdepnulrsti_dX/modelStruct.modelVar_wdepnulrsti/modelStruct.modelVar_wdepnulrsti);
modelStruct.modelVar_wdepnulrinvsti = (1.0/modelStruct.modelVar_wdepnulrsti);
modelStruct.d_modelVar_wdepnulrinvgat_dX = (-modelStruct.d_modelVar_wdepnulrgat_dX/modelStruct.modelVar_wdepnulrgat/modelStruct.modelVar_wdepnulrgat);
modelStruct.modelVar_wdepnulrinvgat = (1.0/modelStruct.modelVar_wdepnulrgat);
modelStruct.d_modelVar_VBIRBOTinv_dX = (-modelStruct.d_modelVar_VBIRBOT_i_dX/modelStruct.modelVar_VBIRBOT_i/modelStruct.modelVar_VBIRBOT_i);
modelStruct.modelVar_VBIRBOTinv = (1.0/modelStruct.modelVar_VBIRBOT_i);
modelStruct.d_modelVar_VBIRSTIinv_dX = (-modelStruct.d_modelVar_VBIRSTI_i_dX/modelStruct.modelVar_VBIRSTI_i/modelStruct.modelVar_VBIRSTI_i);
modelStruct.modelVar_VBIRSTIinv = (1.0/modelStruct.modelVar_VBIRSTI_i);
modelStruct.d_modelVar_VBIRGATinv_dX = (-modelStruct.d_modelVar_VBIRGAT_i_dX/modelStruct.modelVar_VBIRGAT_i/modelStruct.modelVar_VBIRGAT_i);
modelStruct.modelVar_VBIRGATinv = (1.0/modelStruct.modelVar_VBIRGAT_i);
modelStruct.modelVar_perfc = (1.77245385090551603*0.29214664);
{
double value_pow_0 = pow(modelStruct.modelVar_perfc,(-2.0));
modelStruct.modelVar_berfc = (((((-5.0)*0.29214664)+6.0)-value_pow_0)/3.0);
}
modelStruct.modelVar_cerfc = ((1.0-0.29214664)-modelStruct.modelVar_berfc);
{
double value_max_0 = std::max((0.5*phigdbot),modelStruct.modelVar_phitd);
double  deriv_max_0_d0 = (((0.5*phigdbot)>=modelStruct.modelVar_phitd)?1.0:0.0);
double  deriv_max_0_d1 = (((0.5*phigdbot)>=modelStruct.modelVar_phitd)?0.0:1.0);
d_deltaEbot_dX = ((deriv_max_0_d0*(0.5*d_phigdbot_dX))+(deriv_max_0_d1*(modelStruct.d_modelVar_phitd_dX)));
deltaEbot = value_max_0;
}
{
double value_max_0 = std::max((0.5*phigdsti),modelStruct.modelVar_phitd);
double  deriv_max_0_d0 = (((0.5*phigdsti)>=modelStruct.modelVar_phitd)?1.0:0.0);
double  deriv_max_0_d1 = (((0.5*phigdsti)>=modelStruct.modelVar_phitd)?0.0:1.0);
d_deltaEsti_dX = ((deriv_max_0_d0*(0.5*d_phigdsti_dX))+(deriv_max_0_d1*(modelStruct.d_modelVar_phitd_dX)));
deltaEsti = value_max_0;
}
{
double value_max_0 = std::max((0.5*phigdgat),modelStruct.modelVar_phitd);
double  deriv_max_0_d0 = (((0.5*phigdgat)>=modelStruct.modelVar_phitd)?1.0:0.0);
double  deriv_max_0_d1 = (((0.5*phigdgat)>=modelStruct.modelVar_phitd)?0.0:1.0);
d_deltaEgat_dX = ((deriv_max_0_d0*(0.5*d_phigdgat_dX))+(deriv_max_0_d1*(modelStruct.d_modelVar_phitd_dX)));
deltaEgat = value_max_0;
}
modelStruct.d_modelVar_atatbot_dX = (deltaEbot*modelStruct.d_modelVar_phitdinv_dX+d_deltaEbot_dX*modelStruct.modelVar_phitdinv);
modelStruct.modelVar_atatbot = (deltaEbot*modelStruct.modelVar_phitdinv);
modelStruct.d_modelVar_atatsti_dX = (deltaEsti*modelStruct.d_modelVar_phitdinv_dX+d_deltaEsti_dX*modelStruct.modelVar_phitdinv);
modelStruct.modelVar_atatsti = (deltaEsti*modelStruct.modelVar_phitdinv);
modelStruct.d_modelVar_atatgat_dX = (deltaEgat*modelStruct.d_modelVar_phitdinv_dX+d_deltaEgat_dX*modelStruct.modelVar_phitdinv);
modelStruct.modelVar_atatgat = (deltaEgat*modelStruct.modelVar_phitdinv);
{
double value_sqrt_0 = sqrt(((((32.0*MEFFTATBOT_i)*9.1093826E-31)*1.6021918E-19)*((deltaEbot*deltaEbot)*deltaEbot)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
modelStruct.d_modelVar_btatpartbot_dX = (deriv_sqrt_0_d0*(((((32.0*MEFFTATBOT_i)*9.1093826E-31)*1.6021918E-19)*((deltaEbot*deltaEbot)*d_deltaEbot_dX+(deltaEbot*d_deltaEbot_dX+d_deltaEbot_dX*deltaEbot)*deltaEbot)+32.0*d_MEFFTATBOT_i_dX*9.1093826E-31*1.6021918E-19*((deltaEbot*deltaEbot)*deltaEbot)))/(3.0*1.05457168E-34));
modelStruct.modelVar_btatpartbot = (value_sqrt_0/(3.0*1.05457168E-34));
}
{
double value_sqrt_0 = sqrt(((((32.0*MEFFTATSTI_i)*9.1093826E-31)*1.6021918E-19)*((deltaEsti*deltaEsti)*deltaEsti)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
modelStruct.d_modelVar_btatpartsti_dX = (deriv_sqrt_0_d0*(((((32.0*MEFFTATSTI_i)*9.1093826E-31)*1.6021918E-19)*((deltaEsti*deltaEsti)*d_deltaEsti_dX+(deltaEsti*d_deltaEsti_dX+d_deltaEsti_dX*deltaEsti)*deltaEsti)+32.0*d_MEFFTATSTI_i_dX*9.1093826E-31*1.6021918E-19*((deltaEsti*deltaEsti)*deltaEsti)))/(3.0*1.05457168E-34));
modelStruct.modelVar_btatpartsti = (value_sqrt_0/(3.0*1.05457168E-34));
}
{
double value_sqrt_0 = sqrt(((((32.0*MEFFTATGAT_i)*9.1093826E-31)*1.6021918E-19)*((deltaEgat*deltaEgat)*deltaEgat)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
modelStruct.d_modelVar_btatpartgat_dX = (deriv_sqrt_0_d0*(((((32.0*MEFFTATGAT_i)*9.1093826E-31)*1.6021918E-19)*((deltaEgat*deltaEgat)*d_deltaEgat_dX+(deltaEgat*d_deltaEgat_dX+d_deltaEgat_dX*deltaEgat)*deltaEgat)+32.0*d_MEFFTATGAT_i_dX*9.1093826E-31*1.6021918E-19*((deltaEgat*deltaEgat)*deltaEgat)))/(3.0*1.05457168E-34));
modelStruct.modelVar_btatpartgat = (value_sqrt_0/(3.0*1.05457168E-34));
}
modelStruct.d_modelVar_fbbtbot_dX = (FBBTRBOT_i*(STFBBTBOT_i*(d_tkd_dX-d_tkr_dX)+d_STFBBTBOT_i_dX*(tkd-tkr))+d_FBBTRBOT_i_dX*(1.0+(STFBBTBOT_i*(tkd-tkr))));
modelStruct.modelVar_fbbtbot = (FBBTRBOT_i*(1.0+(STFBBTBOT_i*(tkd-tkr))));
modelStruct.d_modelVar_fbbtsti_dX = (FBBTRSTI_i*(STFBBTSTI_i*(d_tkd_dX-d_tkr_dX)+d_STFBBTSTI_i_dX*(tkd-tkr))+d_FBBTRSTI_i_dX*(1.0+(STFBBTSTI_i*(tkd-tkr))));
modelStruct.modelVar_fbbtsti = (FBBTRSTI_i*(1.0+(STFBBTSTI_i*(tkd-tkr))));
modelStruct.d_modelVar_fbbtgat_dX = (FBBTRGAT_i*(STFBBTGAT_i*(d_tkd_dX-d_tkr_dX)+d_STFBBTGAT_i_dX*(tkd-tkr))+d_FBBTRGAT_i_dX*(1.0+(STFBBTGAT_i*(tkd-tkr))));
modelStruct.modelVar_fbbtgat = (FBBTRGAT_i*(1.0+(STFBBTGAT_i*(tkd-tkr))));
modelStruct.d_modelVar_fbbtbot_dX = ((modelStruct.modelVar_fbbtbot>0.0)?modelStruct.d_modelVar_fbbtbot_dX:0.0);
modelStruct.modelVar_fbbtbot = ((modelStruct.modelVar_fbbtbot>0.0)?modelStruct.modelVar_fbbtbot:0.0);
modelStruct.d_modelVar_fbbtsti_dX = ((modelStruct.modelVar_fbbtsti>0.0)?modelStruct.d_modelVar_fbbtsti_dX:0.0);
modelStruct.modelVar_fbbtsti = ((modelStruct.modelVar_fbbtsti>0.0)?modelStruct.modelVar_fbbtsti:0.0);
modelStruct.d_modelVar_fbbtgat_dX = ((modelStruct.modelVar_fbbtgat>0.0)?modelStruct.d_modelVar_fbbtgat_dX:0.0);
modelStruct.modelVar_fbbtgat = ((modelStruct.modelVar_fbbtgat>0.0)?modelStruct.modelVar_fbbtgat:0.0);
modelStruct.d_modelVar_alphaav_dX = (-(-d_FREV_i_dX/FREV_i/FREV_i));
modelStruct.modelVar_alphaav = (1.0-(1.0/FREV_i));
{
double value_pow_0 = pow(modelStruct.modelVar_alphaav,modelStruct.modelVar_PBRBOT_i);
double  deriv_pow_0_d0 = ((modelStruct.modelVar_alphaav == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBRBOT_i/modelStruct.modelVar_alphaav));
double  deriv_pow_0_d1 = (modelStruct.modelVar_alphaav == 0.0)?0.0:(log(modelStruct.modelVar_alphaav)*value_pow_0);
modelStruct.d_modelVar_fstopbot_dX = (-(-((deriv_pow_0_d0*(modelStruct.d_modelVar_alphaav_dX))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBRBOT_i_dX))))/(1.0-value_pow_0)/(1.0-value_pow_0));
modelStruct.modelVar_fstopbot = (1.0/(1.0-value_pow_0));
}
{
double value_pow_0 = pow(modelStruct.modelVar_alphaav,modelStruct.modelVar_PBRSTI_i);
double  deriv_pow_0_d0 = ((modelStruct.modelVar_alphaav == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBRSTI_i/modelStruct.modelVar_alphaav));
double  deriv_pow_0_d1 = (modelStruct.modelVar_alphaav == 0.0)?0.0:(log(modelStruct.modelVar_alphaav)*value_pow_0);
modelStruct.d_modelVar_fstopsti_dX = (-(-((deriv_pow_0_d0*(modelStruct.d_modelVar_alphaav_dX))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBRSTI_i_dX))))/(1.0-value_pow_0)/(1.0-value_pow_0));
modelStruct.modelVar_fstopsti = (1.0/(1.0-value_pow_0));
}
{
double value_pow_0 = pow(modelStruct.modelVar_alphaav,modelStruct.modelVar_PBRGAT_i);
double  deriv_pow_0_d0 = ((modelStruct.modelVar_alphaav == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBRGAT_i/modelStruct.modelVar_alphaav));
double  deriv_pow_0_d1 = (modelStruct.modelVar_alphaav == 0.0)?0.0:(log(modelStruct.modelVar_alphaav)*value_pow_0);
modelStruct.d_modelVar_fstopgat_dX = (-(-((deriv_pow_0_d0*(modelStruct.d_modelVar_alphaav_dX))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBRGAT_i_dX))))/(1.0-value_pow_0)/(1.0-value_pow_0));
modelStruct.modelVar_fstopgat = (1.0/(1.0-value_pow_0));
}
modelStruct.d_modelVar_VBRinvbot_dX = (-modelStruct.d_modelVar_VBRBOT_i_dX/modelStruct.modelVar_VBRBOT_i/modelStruct.modelVar_VBRBOT_i);
modelStruct.modelVar_VBRinvbot = (1.0/modelStruct.modelVar_VBRBOT_i);
modelStruct.d_modelVar_VBRinvsti_dX = (-modelStruct.d_modelVar_VBRSTI_i_dX/modelStruct.modelVar_VBRSTI_i/modelStruct.modelVar_VBRSTI_i);
modelStruct.modelVar_VBRinvsti = (1.0/modelStruct.modelVar_VBRSTI_i);
modelStruct.d_modelVar_VBRinvgat_dX = (-modelStruct.d_modelVar_VBRGAT_i_dX/modelStruct.modelVar_VBRGAT_i/modelStruct.modelVar_VBRGAT_i);
modelStruct.modelVar_VBRinvgat = (1.0/modelStruct.modelVar_VBRGAT_i);
{
double value_pow_0 = pow(modelStruct.modelVar_alphaav,(modelStruct.modelVar_PBRBOT_i-1.0));
double  deriv_pow_0_d0 = ((modelStruct.modelVar_alphaav == 0.0)?0.0:(value_pow_0*(modelStruct.modelVar_PBRBOT_i-1.0)/modelStruct.modelVar_alphaav));
double  deriv_pow_0_d1 = (modelStruct.modelVar_alphaav == 0.0)?0.0:(log(modelStruct.modelVar_alphaav)*value_pow_0);
modelStruct.d_modelVar_slopebot_dX = (((-((modelStruct.modelVar_fstopbot*modelStruct.modelVar_fstopbot)*value_pow_0))*modelStruct.modelVar_PBRBOT_i)*modelStruct.d_modelVar_VBRinvbot_dX+((-((modelStruct.modelVar_fstopbot*modelStruct.modelVar_fstopbot)*value_pow_0))*modelStruct.d_modelVar_PBRBOT_i_dX+(-((modelStruct.modelVar_fstopbot*modelStruct.modelVar_fstopbot)*((deriv_pow_0_d0*(modelStruct.d_modelVar_alphaav_dX))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBRBOT_i_dX)))+(modelStruct.modelVar_fstopbot*modelStruct.d_modelVar_fstopbot_dX+modelStruct.d_modelVar_fstopbot_dX*modelStruct.modelVar_fstopbot)*value_pow_0))*modelStruct.modelVar_PBRBOT_i)*modelStruct.modelVar_VBRinvbot);
modelStruct.modelVar_slopebot = (((-((modelStruct.modelVar_fstopbot*modelStruct.modelVar_fstopbot)*value_pow_0))*modelStruct.modelVar_PBRBOT_i)*modelStruct.modelVar_VBRinvbot);
}
{
double value_pow_0 = pow(modelStruct.modelVar_alphaav,(modelStruct.modelVar_PBRSTI_i-1.0));
double  deriv_pow_0_d0 = ((modelStruct.modelVar_alphaav == 0.0)?0.0:(value_pow_0*(modelStruct.modelVar_PBRSTI_i-1.0)/modelStruct.modelVar_alphaav));
double  deriv_pow_0_d1 = (modelStruct.modelVar_alphaav == 0.0)?0.0:(log(modelStruct.modelVar_alphaav)*value_pow_0);
modelStruct.d_modelVar_slopesti_dX = (((-((modelStruct.modelVar_fstopsti*modelStruct.modelVar_fstopsti)*value_pow_0))*modelStruct.modelVar_PBRSTI_i)*modelStruct.d_modelVar_VBRinvsti_dX+((-((modelStruct.modelVar_fstopsti*modelStruct.modelVar_fstopsti)*value_pow_0))*modelStruct.d_modelVar_PBRSTI_i_dX+(-((modelStruct.modelVar_fstopsti*modelStruct.modelVar_fstopsti)*((deriv_pow_0_d0*(modelStruct.d_modelVar_alphaav_dX))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBRSTI_i_dX)))+(modelStruct.modelVar_fstopsti*modelStruct.d_modelVar_fstopsti_dX+modelStruct.d_modelVar_fstopsti_dX*modelStruct.modelVar_fstopsti)*value_pow_0))*modelStruct.modelVar_PBRSTI_i)*modelStruct.modelVar_VBRinvsti);
modelStruct.modelVar_slopesti = (((-((modelStruct.modelVar_fstopsti*modelStruct.modelVar_fstopsti)*value_pow_0))*modelStruct.modelVar_PBRSTI_i)*modelStruct.modelVar_VBRinvsti);
}
{
double value_pow_0 = pow(modelStruct.modelVar_alphaav,(modelStruct.modelVar_PBRGAT_i-1.0));
double  deriv_pow_0_d0 = ((modelStruct.modelVar_alphaav == 0.0)?0.0:(value_pow_0*(modelStruct.modelVar_PBRGAT_i-1.0)/modelStruct.modelVar_alphaav));
double  deriv_pow_0_d1 = (modelStruct.modelVar_alphaav == 0.0)?0.0:(log(modelStruct.modelVar_alphaav)*value_pow_0);
modelStruct.d_modelVar_slopegat_dX = (((-((modelStruct.modelVar_fstopgat*modelStruct.modelVar_fstopgat)*value_pow_0))*modelStruct.modelVar_PBRGAT_i)*modelStruct.d_modelVar_VBRinvgat_dX+((-((modelStruct.modelVar_fstopgat*modelStruct.modelVar_fstopgat)*value_pow_0))*modelStruct.d_modelVar_PBRGAT_i_dX+(-((modelStruct.modelVar_fstopgat*modelStruct.modelVar_fstopgat)*((deriv_pow_0_d0*(modelStruct.d_modelVar_alphaav_dX))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBRGAT_i_dX)))+(modelStruct.modelVar_fstopgat*modelStruct.d_modelVar_fstopgat_dX+modelStruct.d_modelVar_fstopgat_dX*modelStruct.modelVar_fstopgat)*value_pow_0))*modelStruct.modelVar_PBRGAT_i)*modelStruct.modelVar_VBRinvgat);
modelStruct.modelVar_slopegat = (((-((modelStruct.modelVar_fstopgat*modelStruct.modelVar_fstopgat)*value_pow_0))*modelStruct.modelVar_PBRGAT_i)*modelStruct.modelVar_VBRinvgat);
}
}
// End block initial_model
}



//-----------------------------------------------------------------------------
// Function      : evaluateModelEquations
// Purpose       : Evaluate the main module block.  Similar to
//                 updateIntermediateVars, but takes all instance and model
//                 parameters and variables as arguments instead of using
//                 the ones stored in the objects.
// Special Notes : specific for sensitivity use
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
void evaluateModelEquations(
std::vector <double> & probeVars,
// probe constants
const int admsProbeID_V_A_GND,
const int admsProbeID_V_A_K,
// node constants
const int admsNodeID_A,
const int admsNodeID_K,
instanceSensStruct & instanceStruct,
modelSensStruct & modelStruct,
// basic variables
 double admsTemperature, double adms_vt_nom, double ADMSgmin_arg, std::vector <double> & d_staticContributions_dX, std::vector <double> & d_dynamicContributions_dX, const Instance & theInstance)
{

  // Local variables
  double h1=0.0;
double d_h1_dX=0.0;
  double h2=0.0;
double d_h2_dX=0.0;
  double h2d=0.0;
double d_h2d_dX=0.0;
  double h3=0.0;
double d_h3_dX=0.0;
  double h4=0.0;
double d_h4_dX=0.0;
  double h5=0.0;
double d_h5_dX=0.0;
  double ijunrev=0.0;
double d_ijunrev_dX=0.0;
  double ijunfor2=0.0;
double d_ijunfor2_dX=0.0;
  double ijunfor1=0.0;
double d_ijunfor1_dX=0.0;
  double tm1=0.0;
double d_tm1_dX=0.0;
  double tm0=0.0;
double d_tm0_dX=0.0;
  double fbreakdown=0.0;
double d_fbreakdown_dX=0.0;
  double ibbt=0.0;
double d_ibbt_dX=0.0;
  double Fmaxr=0.0;
double d_Fmaxr_dX=0.0;
  double itat=0.0;
double d_itat_dX=0.0;
  double gammamax=0.0;
double d_gammamax_dX=0.0;
  double erfctimesexpmtat=0.0;
double d_erfctimesexpmtat_dX=0.0;
  double erfcpos=0.0;
double d_erfcpos_dX=0.0;
  double terfc=0.0;
double d_terfc_dX=0.0;
  double ysq=0.0;
double d_ysq_dX=0.0;
  double xerfc=0.0;
double d_xerfc_dX=0.0;
  double mtat=0.0;
double d_mtat_dX=0.0;
  double ltat=0.0;
double d_ltat_dX=0.0;
  double ktat=0.0;
double d_ktat_dX=0.0;
  double wtat=0.0;
double d_wtat_dX=0.0;
  double wgamma=0.0;
double d_wgamma_dX=0.0;
  double umaxpoweronepointfive=0.0;
double d_umaxpoweronepointfive_dX=0.0;
  double sqrtumax=0.0;
double d_sqrtumax_dX=0.0;
  double umax=0.0;
double d_umax_dX=0.0;
  double umaxbeforelimiting=0.0;
double d_umaxbeforelimiting_dX=0.0;
  double twoatatoverthreebtat=0.0;
double d_twoatatoverthreebtat_dX=0.0;
  double btat=0.0;
double d_btat_dX=0.0;
  double isrh=0.0;
double d_isrh_dX=0.0;
  double asrh=0.0;
double d_asrh_dX=0.0;
  double wdep=0.0;
double d_wdep_dX=0.0;
  double wsrh=0.0;
double d_wsrh_dX=0.0;
  double dwsrh=0.0;
double d_dwsrh_dX=0.0;
  double wsrhstep=0.0;
double d_wsrhstep_dX=0.0;
  double vbi_minus_vjsrh=0.0;
double d_vbi_minus_vjsrh_dX=0.0;
  double id=0.0;
double d_id_dX=0.0;
  double tmp=0.0;
double d_tmp_dX=0.0;
  double vav=0.0;
double d_vav_dX=0.0;
  double vjsrh=0.0;
double d_vjsrh_dX=0.0;
  double vjlim=0.0;
double d_vjlim_dX=0.0;
  double z=0.0;
double d_z_dX=0.0;
  double idmult=0.0;
double d_idmult_dX=0.0;
  double zinv=0.0;
double d_zinv_dX=0.0;
  double vj=0.0;
double d_vj_dX=0.0;
  double two_psistar=0.0;
double d_two_psistar_dX=0.0;
  double vbbt=0.0;
double d_vbbt_dX=0.0;


  // -- code converted from analog/code block
//Begin block evaluateblock
{
//Block-local variables for block evaluateblock
double ijunbot=0.0;
double d_ijunbot_dX=0.0;
double qjunbot=0.0;
double d_qjunbot_dX=0.0;
double ijunsti=0.0;
double d_ijunsti_dX=0.0;
double qjunsti=0.0;
double d_qjunsti_dX=0.0;
double ijungat=0.0;
double d_ijungat_dX=0.0;
double qjungat=0.0;
double d_qjungat_dX=0.0;
double ijun=0.0;
double d_ijun_dX=0.0;
double qjun=0.0;
double d_qjun_dX=0.0;
double jnoise=0.0;
double d_jnoise_dX=0.0;
double VAK=0.0;
double d_VAK_dX=0.0;
//End of Block-local variables
d_ijun_dX = 0.0;
ijun = 0.0;
d_ijunbot_dX = 0.0;
ijunbot = 0.0;
d_ijunsti_dX = 0.0;
ijunsti = 0.0;
d_ijungat_dX = 0.0;
ijungat = 0.0;
//Begin block evaluateStaticDynamic
{
d_VAK_dX = 0.0;
VAK = (modelStruct.modelPar_TYPE*(probeVars[admsProbeID_V_A_K]));
if ((modelStruct.modelVar_SWJUNEXP_i==1.0))
{
d_tm0_dX = (VAK*modelStruct.d_modelVar_phitdinv_dX+d_VAK_dX*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR1;
tm0 = ((VAK*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR1);
{
double value_exp_0 = exp(tm0);
double  deriv_exp_0_d0 = value_exp_0;
d_tm1_dX = ((tm0<(-2.3025850929940458e+02))?(-1.0e-100*(-d_tm0_dX)/(((-2.3025850929940458e+02)-tm0)+1.0)/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>instanceStruct.instanceVar_xhighf1)?(instanceStruct.instanceVar_expxhf1*(d_tm0_dX-instanceStruct.d_instanceVar_xhighf1_dX)+instanceStruct.d_instanceVar_expxhf1_dX*((tm0-instanceStruct.instanceVar_xhighf1)+1.0)):deriv_exp_0_d0*(d_tm0_dX)));
tm1 = ((tm0<(-2.3025850929940458e+02))?(1.0e-100/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>instanceStruct.instanceVar_xhighf1)?(instanceStruct.instanceVar_expxhf1*((tm0-instanceStruct.instanceVar_xhighf1)+1.0)):value_exp_0));
}
d_ijunfor1_dX = (instanceStruct.instanceVar_ISATFOR1*d_tm1_dX+instanceStruct.d_instanceVar_ISATFOR1_dX*(tm1-1.0));
ijunfor1 = (instanceStruct.instanceVar_ISATFOR1*(tm1-1.0));
d_tm0_dX = ((VAK*modelStruct.modelVar_phitdinv)*instanceStruct.d_instanceVar_MFOR2_dX+(VAK*modelStruct.d_modelVar_phitdinv_dX+d_VAK_dX*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR2);
tm0 = ((VAK*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MFOR2);
{
double value_exp_0 = exp(tm0);
double  deriv_exp_0_d0 = value_exp_0;
d_tm1_dX = ((tm0<(-2.3025850929940458e+02))?(-1.0e-100*(-d_tm0_dX)/(((-2.3025850929940458e+02)-tm0)+1.0)/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>instanceStruct.instanceVar_xhighf2)?(instanceStruct.instanceVar_expxhf2*(d_tm0_dX-instanceStruct.d_instanceVar_xhighf2_dX)+instanceStruct.d_instanceVar_expxhf2_dX*((tm0-instanceStruct.instanceVar_xhighf2)+1.0)):deriv_exp_0_d0*(d_tm0_dX)));
tm1 = ((tm0<(-2.3025850929940458e+02))?(1.0e-100/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>instanceStruct.instanceVar_xhighf2)?(instanceStruct.instanceVar_expxhf2*((tm0-instanceStruct.instanceVar_xhighf2)+1.0)):value_exp_0));
}
d_ijunfor2_dX = (instanceStruct.instanceVar_ISATFOR2*d_tm1_dX+instanceStruct.d_instanceVar_ISATFOR2_dX*(tm1-1.0));
ijunfor2 = (instanceStruct.instanceVar_ISATFOR2*(tm1-1.0));
d_ijunrev_dX = 0.0;
ijunrev = 0.0;
if ((instanceStruct.instanceVar_m0flag>0.0))
{
d_ijunrev_dX = (VAK*(instanceStruct.d_instanceVar_ISATREV_dX+(VAK*instanceStruct.d_instanceVar_MREV_dX+d_VAK_dX*instanceStruct.instanceVar_MREV))+d_VAK_dX*(instanceStruct.instanceVar_ISATREV+(VAK*instanceStruct.instanceVar_MREV)));
ijunrev = (VAK*(instanceStruct.instanceVar_ISATREV+(VAK*instanceStruct.instanceVar_MREV)));
}
else
{
d_tm0_dX = (((-VAK)*modelStruct.modelVar_phitdinv)*instanceStruct.d_instanceVar_MREV_dX+((-VAK)*modelStruct.d_modelVar_phitdinv_dX+(-d_VAK_dX)*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MREV);
tm0 = (((-VAK)*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_MREV);
{
double value_exp_0 = exp(tm0);
double  deriv_exp_0_d0 = value_exp_0;
d_tm1_dX = ((tm0<(-2.3025850929940458e+02))?(-1.0e-100*(-d_tm0_dX)/(((-2.3025850929940458e+02)-tm0)+1.0)/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>instanceStruct.instanceVar_xhighr)?(instanceStruct.instanceVar_expxhr*(d_tm0_dX-instanceStruct.d_instanceVar_xhighr_dX)+instanceStruct.d_instanceVar_expxhr_dX*((tm0-instanceStruct.instanceVar_xhighr)+1.0)):deriv_exp_0_d0*(d_tm0_dX)));
tm1 = ((tm0<(-2.3025850929940458e+02))?(1.0e-100/(((-2.3025850929940458e+02)-tm0)+1.0)):((tm0>instanceStruct.instanceVar_xhighr)?(instanceStruct.instanceVar_expxhr*((tm0-instanceStruct.instanceVar_xhighr)+1.0)):value_exp_0));
}
d_ijunrev_dX = ((-instanceStruct.instanceVar_ISATREV)*d_tm1_dX+(-instanceStruct.d_instanceVar_ISATREV_dX)*(tm1-1.0));
ijunrev = ((-instanceStruct.instanceVar_ISATREV)*(tm1-1.0));
}
d_ijun_dX = ((d_ijunfor1_dX+d_ijunfor2_dX)+d_ijunrev_dX);
ijun = ((ijunfor1+ijunfor2)+ijunrev);
//Begin block evaluateDynamic
{
//Block-local variables for block evaluateDynamic
double tmpv=0.0;
double d_tmpv_dX=0.0;
double vjv=0.0;
double d_vjv_dX=0.0;
//End of Block-local variables
d_tmpv_dX = 0.0;
tmpv = 0.0;
d_vjv_dX = 0.0;
vjv = 0.0;
d_h1_dX = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.d_instanceVar_vch_dX+4.0*instanceStruct.d_instanceVar_vch_dX*instanceStruct.instanceVar_vch);
h1 = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.instanceVar_vch);
d_h2_dX = ((instanceStruct.instanceVar_vfmin*instanceStruct.d_instanceVar_vch_dX-instanceStruct.instanceVar_vch*instanceStruct.d_instanceVar_vfmin_dX)/instanceStruct.instanceVar_vfmin/instanceStruct.instanceVar_vfmin);
h2 = (instanceStruct.instanceVar_vch/instanceStruct.instanceVar_vfmin);
d_h2d_dX = (d_VAK_dX+(instanceStruct.instanceVar_vch*d_h2_dX+instanceStruct.d_instanceVar_vch_dX*h2));
h2d = (VAK+(instanceStruct.instanceVar_vch*h2));
d_h3_dX = (instanceStruct.d_instanceVar_vfmin_dX+d_h2d_dX);
h3 = (instanceStruct.instanceVar_vfmin+h2d);
d_h4_dX = (instanceStruct.d_instanceVar_vfmin_dX-d_h2d_dX);
h4 = (instanceStruct.instanceVar_vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_h5_dX = deriv_sqrt_0_d0*(((h4*d_h4_dX+d_h4_dX*h4)+d_h1_dX));
h5 = value_sqrt_0;
}
d_vjv_dX = 2.0*(((h3+h5)*(VAK*instanceStruct.d_instanceVar_vfmin_dX+d_VAK_dX*instanceStruct.instanceVar_vfmin)-(VAK*instanceStruct.instanceVar_vfmin)*(d_h3_dX+d_h5_dX))/(h3+h5)/(h3+h5));
vjv = (2.0*((VAK*instanceStruct.instanceVar_vfmin)/(h3+h5)));
if ((instanceStruct.instanceVar_zflagbot>0.5))
{
if ((modelStruct.modelVar_one_minus_PBOT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vjv*modelStruct.modelVar_vbiinvbot)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmpv_dX = deriv_sqrt_0_d0*((-(vjv*modelStruct.d_modelVar_vbiinvbot_dX+d_vjv_dX*modelStruct.modelVar_vbiinvbot)));
tmpv = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vjv*modelStruct.modelVar_vbiinvbot)),modelStruct.modelVar_one_minus_PBOT);
double  deriv_pow_0_d0 = (((1.0-(vjv*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PBOT/(1.0-(vjv*modelStruct.modelVar_vbiinvbot))));
double  deriv_pow_0_d1 = ((1.0-(vjv*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(log((1.0-(vjv*modelStruct.modelVar_vbiinvbot)))*value_pow_0);
d_tmpv_dX = ((deriv_pow_0_d0*((-(vjv*modelStruct.d_modelVar_vbiinvbot_dX+d_vjv_dX*modelStruct.modelVar_vbiinvbot))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PBOT_dX)));
tmpv = value_pow_0;
}
}
d_qjunbot_dX = ((modelStruct.modelVar_qprefbot*(-d_tmpv_dX)+modelStruct.d_modelVar_qprefbot_dX*(1.0-tmpv))+(modelStruct.modelVar_qpref2bot*(d_VAK_dX-d_vjv_dX)+modelStruct.d_modelVar_qpref2bot_dX*(VAK-vjv)));
qjunbot = ((modelStruct.modelVar_qprefbot*(1.0-tmpv))+(modelStruct.modelVar_qpref2bot*(VAK-vjv)));
}
if ((instanceStruct.instanceVar_zflagsti>0.5))
{
if ((modelStruct.modelVar_one_minus_PSTI==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vjv*modelStruct.modelVar_vbiinvsti)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmpv_dX = deriv_sqrt_0_d0*((-(vjv*modelStruct.d_modelVar_vbiinvsti_dX+d_vjv_dX*modelStruct.modelVar_vbiinvsti)));
tmpv = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vjv*modelStruct.modelVar_vbiinvsti)),modelStruct.modelVar_one_minus_PSTI);
double  deriv_pow_0_d0 = (((1.0-(vjv*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PSTI/(1.0-(vjv*modelStruct.modelVar_vbiinvsti))));
double  deriv_pow_0_d1 = ((1.0-(vjv*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(log((1.0-(vjv*modelStruct.modelVar_vbiinvsti)))*value_pow_0);
d_tmpv_dX = ((deriv_pow_0_d0*((-(vjv*modelStruct.d_modelVar_vbiinvsti_dX+d_vjv_dX*modelStruct.modelVar_vbiinvsti))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PSTI_dX)));
tmpv = value_pow_0;
}
}
d_qjunsti_dX = ((modelStruct.modelVar_qprefsti*(-d_tmpv_dX)+modelStruct.d_modelVar_qprefsti_dX*(1.0-tmpv))+(modelStruct.modelVar_qpref2sti*(d_VAK_dX-d_vjv_dX)+modelStruct.d_modelVar_qpref2sti_dX*(VAK-vjv)));
qjunsti = ((modelStruct.modelVar_qprefsti*(1.0-tmpv))+(modelStruct.modelVar_qpref2sti*(VAK-vjv)));
}
if ((instanceStruct.instanceVar_zflaggat>0.5))
{
if ((modelStruct.modelVar_one_minus_PGAT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vjv*modelStruct.modelVar_vbiinvgat)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmpv_dX = deriv_sqrt_0_d0*((-(vjv*modelStruct.d_modelVar_vbiinvgat_dX+d_vjv_dX*modelStruct.modelVar_vbiinvgat)));
tmpv = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vjv*modelStruct.modelVar_vbiinvgat)),modelStruct.modelVar_one_minus_PGAT);
double  deriv_pow_0_d0 = (((1.0-(vjv*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PGAT/(1.0-(vjv*modelStruct.modelVar_vbiinvgat))));
double  deriv_pow_0_d1 = ((1.0-(vjv*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(log((1.0-(vjv*modelStruct.modelVar_vbiinvgat)))*value_pow_0);
d_tmpv_dX = ((deriv_pow_0_d0*((-(vjv*modelStruct.d_modelVar_vbiinvgat_dX+d_vjv_dX*modelStruct.modelVar_vbiinvgat))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PGAT_dX)));
tmpv = value_pow_0;
}
}
d_qjungat_dX = ((modelStruct.modelVar_qprefgat*(-d_tmpv_dX)+modelStruct.d_modelVar_qprefgat_dX*(1.0-tmpv))+(modelStruct.modelVar_qpref2gat*(d_VAK_dX-d_vjv_dX)+modelStruct.d_modelVar_qpref2gat_dX*(VAK-vjv)));
qjungat = ((modelStruct.modelVar_qprefgat*(1.0-tmpv))+(modelStruct.modelVar_qpref2gat*(VAK-vjv)));
}
}
// End block evaluateDynamic
}
else
{
d_vbbt_dX = 0.0;
vbbt = 0.0;
d_two_psistar_dX = 0.0;
two_psistar = 0.0;
if ((!(((instanceStruct.instanceVar_AB_i==0.0)&&(instanceStruct.instanceVar_LS_i==0.0))&&(instanceStruct.instanceVar_LG_i==0.0))))
{
d_h1_dX = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.d_instanceVar_vch_dX+4.0*instanceStruct.d_instanceVar_vch_dX*instanceStruct.instanceVar_vch);
h1 = ((4.0*instanceStruct.instanceVar_vch)*instanceStruct.instanceVar_vch);
d_h2_dX = ((instanceStruct.instanceVar_vfmin*instanceStruct.d_instanceVar_vch_dX-instanceStruct.instanceVar_vch*instanceStruct.d_instanceVar_vfmin_dX)/instanceStruct.instanceVar_vfmin/instanceStruct.instanceVar_vfmin);
h2 = (instanceStruct.instanceVar_vch/instanceStruct.instanceVar_vfmin);
d_h2d_dX = (d_VAK_dX+(instanceStruct.instanceVar_vch*d_h2_dX+instanceStruct.d_instanceVar_vch_dX*h2));
h2d = (VAK+(instanceStruct.instanceVar_vch*h2));
d_h3_dX = (instanceStruct.d_instanceVar_vfmin_dX+d_h2d_dX);
h3 = (instanceStruct.instanceVar_vfmin+h2d);
d_h4_dX = (instanceStruct.d_instanceVar_vfmin_dX-d_h2d_dX);
h4 = (instanceStruct.instanceVar_vfmin-h2d);
{
double value_sqrt_0 = sqrt(((h4*h4)+h1));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_h5_dX = deriv_sqrt_0_d0*(((h4*d_h4_dX+d_h4_dX*h4)+d_h1_dX));
h5 = value_sqrt_0;
}
d_vj_dX = 2.0*(((h3+h5)*(VAK*instanceStruct.d_instanceVar_vfmin_dX+d_VAK_dX*instanceStruct.instanceVar_vfmin)-(VAK*instanceStruct.instanceVar_vfmin)*(d_h3_dX+d_h5_dX))/(h3+h5)/(h3+h5));
vj = (2.0*((VAK*instanceStruct.instanceVar_vfmin)/(h3+h5)));
if ((VAK<instanceStruct.instanceVar_VMAX))
{
if ((fabs((0.5*(VAK*modelStruct.modelVar_phitdinv)))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp((0.5*(VAK*modelStruct.modelVar_phitdinv)));
double  deriv_exp_0_d0 = value_exp_0;
d_zinv_dX = deriv_exp_0_d0*(0.5*(VAK*modelStruct.d_modelVar_phitdinv_dX+d_VAK_dX*modelStruct.modelVar_phitdinv));
zinv = value_exp_0;
}
}
else
{
if (((0.5*(VAK*modelStruct.modelVar_phitdinv))<0.0))
{
d_zinv_dX = (-1.0e-100*(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*0.5*(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*(-0.5*(VAK*modelStruct.d_modelVar_phitdinv_dX+d_VAK_dX*modelStruct.modelVar_phitdinv))*3.3333333333333333e-01+(-0.5*(VAK*modelStruct.d_modelVar_phitdinv_dX+d_VAK_dX*modelStruct.modelVar_phitdinv))*(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))+(-0.5*(VAK*modelStruct.d_modelVar_phitdinv_dX+d_VAK_dX*modelStruct.modelVar_phitdinv))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
zinv = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*(1.0+(0.5*(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*(1.0+(((-2.3025850929940458e+02)-(0.5*(VAK*modelStruct.modelVar_phitdinv)))*3.3333333333333333e-01))))))));
}
else
{
d_zinv_dX = 1.0e100*(((0.5*(VAK*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*(((0.5*(VAK*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*0.5*(VAK*modelStruct.d_modelVar_phitdinv_dX+d_VAK_dX*modelStruct.modelVar_phitdinv)*3.3333333333333333e-01+0.5*(VAK*modelStruct.d_modelVar_phitdinv_dX+d_VAK_dX*modelStruct.modelVar_phitdinv)*(1.0+(((0.5*(VAK*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01)))+0.5*(VAK*modelStruct.d_modelVar_phitdinv_dX+d_VAK_dX*modelStruct.modelVar_phitdinv)*(1.0+(0.5*(((0.5*(VAK*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(VAK*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))));
zinv = (1.0e100*(1.0+(((0.5*(VAK*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(0.5*(((0.5*(VAK*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*(1.0+(((0.5*(VAK*modelStruct.modelVar_phitdinv))-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_idmult_dX = (zinv*d_zinv_dX+d_zinv_dX*zinv);
idmult = (zinv*zinv);
}
else
{
d_idmult_dX = ((1.0+((VAK-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX+((VAK-instanceStruct.instanceVar_VMAX)*modelStruct.d_modelVar_phitdinv_dX+(d_VAK_dX-instanceStruct.d_instanceVar_VMAX_dX)*modelStruct.modelVar_phitdinv)*instanceStruct.instanceVar_exp_VMAX_over_phitd);
idmult = ((1.0+((VAK-instanceStruct.instanceVar_VMAX)*modelStruct.modelVar_phitdinv))*instanceStruct.instanceVar_exp_VMAX_over_phitd);
{
double value_sqrt_0 = sqrt(idmult);
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_zinv_dX = deriv_sqrt_0_d0*(d_idmult_dX);
zinv = value_sqrt_0;
}
}
idmult = (idmult-1.0);
d_z_dX = (-d_zinv_dX/zinv/zinv);
z = (1.0/zinv);
if ((VAK>0.0))
{
{
double value_sqrt_0 = sqrt(((z+1.0)*(z+3.0)));
double value_log_1 = log(((2.0+z)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/((2.0+z)+value_sqrt_0));
d_two_psistar_dX = 2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((d_z_dX+deriv_sqrt_0_d0*(((z+1.0)*d_z_dX+d_z_dX*(z+3.0)))))+modelStruct.d_modelVar_phitd_dX*value_log_1);
two_psistar = (2.0*(modelStruct.modelVar_phitd*value_log_1));
}
}
else
{
{
double value_sqrt_0 = sqrt(((1.0+zinv)*(1.0+(3.0*zinv))));
double value_log_1 = log((((2.0*zinv)+1.0)+value_sqrt_0));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
double  deriv_log_1_d0 = (1.0/(((2.0*zinv)+1.0)+value_sqrt_0));
d_two_psistar_dX = ((-d_VAK_dX)+2.0*(modelStruct.modelVar_phitd*deriv_log_1_d0*((2.0*d_zinv_dX+deriv_sqrt_0_d0*(((1.0+zinv)*3.0*d_zinv_dX+d_zinv_dX*(1.0+(3.0*zinv))))))+modelStruct.d_modelVar_phitd_dX*value_log_1));
two_psistar = ((-VAK)+(2.0*(modelStruct.modelVar_phitd*value_log_1)));
}
}
d_vjlim_dX = (instanceStruct.d_instanceVar_vbimin_dX-d_two_psistar_dX);
vjlim = (instanceStruct.instanceVar_vbimin-two_psistar);
{
double value_sqrt_0 = sqrt((((VAK-vjlim)*(VAK-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.modelVar_phitd)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vjsrh_dX = 0.5*((d_VAK_dX+d_vjlim_dX)-deriv_sqrt_0_d0*((((VAK-vjlim)*(d_VAK_dX-d_vjlim_dX)+(d_VAK_dX-d_vjlim_dX)*(VAK-vjlim))+((4.0*modelStruct.modelVar_phitd)*modelStruct.d_modelVar_phitd_dX+4.0*modelStruct.d_modelVar_phitd_dX*modelStruct.modelVar_phitd))));
vjsrh = (0.5*((VAK+vjlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((VAK-instanceStruct.instanceVar_vbbtlim)*(VAK-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.modelVar_phitr)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vbbt_dX = 0.5*((d_VAK_dX+instanceStruct.d_instanceVar_vbbtlim_dX)-deriv_sqrt_0_d0*((((VAK-instanceStruct.instanceVar_vbbtlim)*(d_VAK_dX-instanceStruct.d_instanceVar_vbbtlim_dX)+(d_VAK_dX-instanceStruct.d_instanceVar_vbbtlim_dX)*(VAK-instanceStruct.instanceVar_vbbtlim))+((4.0*modelStruct.modelVar_phitr)*modelStruct.d_modelVar_phitr_dX+4.0*modelStruct.d_modelVar_phitr_dX*modelStruct.modelVar_phitr))));
vbbt = (0.5*((VAK+instanceStruct.instanceVar_vbbtlim)-value_sqrt_0));
}
{
double value_sqrt_0 = sqrt((((VAK)*(VAK))+((4.0*1.0e-6)*1.0e-6)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_vav_dX = 0.5*(d_VAK_dX-deriv_sqrt_0_d0*(((VAK)*d_VAK_dX+d_VAK_dX*(VAK))));
vav = (0.5*(VAK-value_sqrt_0));
}
}
if ((instanceStruct.instanceVar_AB_i==0.0))
{
d_ijunbot_dX = 0.0;
ijunbot = 0.0;
d_qjunbot_dX = 0.0;
qjunbot = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PBOT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvbot)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvbot)),modelStruct.modelVar_one_minus_PBOT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PBOT/(1.0-(vj*modelStruct.modelVar_vbiinvbot))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvbot)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvbot)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvbot_dX+d_vj_dX*modelStruct.modelVar_vbiinvbot))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PBOT_dX)));
tmp = value_pow_0;
}
}
d_qjunbot_dX = ((modelStruct.modelVar_qprefbot*(-d_tmp_dX)+modelStruct.d_modelVar_qprefbot_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(d_VAK_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2bot_dX*(VAK-vj)));
qjunbot = ((modelStruct.modelVar_qprefbot*(1.0-tmp))+(modelStruct.modelVar_qpref2bot*(VAK-vj)));
d_id_dX = (modelStruct.modelVar_idsatbot*d_idmult_dX+modelStruct.d_modelVar_idsatbot_dX*idmult);
id = (modelStruct.modelVar_idsatbot*idmult);
if (((modelStruct.modelVar_CSRHBOT_i==0.0)&&(modelStruct.modelVar_CTATBOT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbibot_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbibot-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PBOT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PBOT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PBOT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRBOTinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrbot*d_tmp_dX+modelStruct.d_modelVar_wdepnulrbot_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrbot*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdbot*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdbot_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdbot*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHBOT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHBOT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHBOT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATBOT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartbot*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PBOT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PBOT)-(wdep*modelStruct.modelVar_one_minus_PBOT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartbot_dX*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartbot*((wdep*modelStruct.modelVar_one_minus_PBOT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatbot_dX-(0.666666666666667*modelStruct.modelVar_atatbot)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatbot)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PBOT_i)*modelStruct.modelVar_one_over_one_minus_PBOT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PBOT_i)*modelStruct.d_modelVar_one_over_one_minus_PBOT_dX+(-modelStruct.d_modelVar_PBOT_i_dX)*modelStruct.modelVar_one_over_one_minus_PBOT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatbot*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatbot_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*d_umax_dX+modelStruct.d_modelVar_atatbot_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatbot*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatbot*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatbot*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatbot_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatbot*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatbot*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATBOT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATBOT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTBOT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PBOT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv),modelStruct.modelVar_PBOT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PBOT_i/((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_VBIRBOTinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_VBIRBOTinv_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRBOTinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PBOT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PBOT*((tmp*((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvbot_dX+(modelStruct.d_modelVar_VBIRBOT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvbot)-((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PBOT_dX*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PBOT*(((modelStruct.modelVar_VBIRBOT_i-vbbt)*modelStruct.modelVar_wdepnulrinvbot)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtbot)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtbot)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtbot)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtbot)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtbot_dX)-(-modelStruct.modelVar_fbbtbot)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtbot)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTBOT_i*(((VAK*Fmaxr)*Fmaxr)*d_tmp_dX+((VAK*Fmaxr)*d_Fmaxr_dX+(VAK*d_Fmaxr_dX+d_VAK_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTBOT_i_dX*(((VAK*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTBOT_i*(((VAK*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRBOT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRBOT_i)))
{
if ((modelStruct.modelVar_PBRBOT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)+(vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
tmp = ((((vav*modelStruct.modelVar_VBRinvbot)*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot))*(vav*modelStruct.modelVar_VBRinvbot));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvbot));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRBOT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvbot))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRBOT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvbot_dX+d_vav_dX*modelStruct.modelVar_VBRinvbot))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRBOT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopbot_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.d_modelVar_slopebot_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRBOT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
fbreakdown = (modelStruct.modelVar_fstopbot+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRBOT_i))*modelStruct.modelVar_slopebot));
}
}
d_ijunbot_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunbot = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LS_i==0.0))
{
d_ijunsti_dX = 0.0;
ijunsti = 0.0;
d_qjunsti_dX = 0.0;
qjunsti = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PSTI==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvsti)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvsti)),modelStruct.modelVar_one_minus_PSTI);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PSTI/(1.0-(vj*modelStruct.modelVar_vbiinvsti))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvsti)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvsti)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvsti_dX+d_vj_dX*modelStruct.modelVar_vbiinvsti))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PSTI_dX)));
tmp = value_pow_0;
}
}
d_qjunsti_dX = ((modelStruct.modelVar_qprefsti*(-d_tmp_dX)+modelStruct.d_modelVar_qprefsti_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(d_VAK_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2sti_dX*(VAK-vj)));
qjunsti = ((modelStruct.modelVar_qprefsti*(1.0-tmp))+(modelStruct.modelVar_qpref2sti*(VAK-vj)));
d_id_dX = (modelStruct.modelVar_idsatsti*d_idmult_dX+modelStruct.d_modelVar_idsatsti_dX*idmult);
id = (modelStruct.modelVar_idsatsti*idmult);
if (((modelStruct.modelVar_CSRHSTI_i==0.0)&&(modelStruct.modelVar_CTATSTI_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbisti_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbisti-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PSTI_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PSTI_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PSTI_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRSTIinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrsti*d_tmp_dX+modelStruct.d_modelVar_wdepnulrsti_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrsti*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdsti*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdsti_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdsti*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHSTI_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHSTI_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHSTI_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATSTI_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartsti*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PSTI_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PSTI)-(wdep*modelStruct.modelVar_one_minus_PSTI)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartsti_dX*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartsti*((wdep*modelStruct.modelVar_one_minus_PSTI)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatsti_dX-(0.666666666666667*modelStruct.modelVar_atatsti)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatsti)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PSTI_i)*modelStruct.modelVar_one_over_one_minus_PSTI)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PSTI_i)*modelStruct.d_modelVar_one_over_one_minus_PSTI_dX+(-modelStruct.d_modelVar_PSTI_i_dX)*modelStruct.modelVar_one_over_one_minus_PSTI))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatsti*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatsti_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*d_umax_dX+modelStruct.d_modelVar_atatsti_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatsti*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatsti*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatsti*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatsti_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatsti*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatsti*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATSTI_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATSTI_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTSTI_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PSTI_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv),modelStruct.modelVar_PSTI_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PSTI_i/((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_VBIRSTIinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_VBIRSTIinv_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRSTIinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PSTI_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PSTI*((tmp*((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvsti_dX+(modelStruct.d_modelVar_VBIRSTI_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvsti)-((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PSTI_dX*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PSTI*(((modelStruct.modelVar_VBIRSTI_i-vbbt)*modelStruct.modelVar_wdepnulrinvsti)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtsti)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtsti)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtsti)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtsti)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtsti_dX)-(-modelStruct.modelVar_fbbtsti)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtsti)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTSTI_i*(((VAK*Fmaxr)*Fmaxr)*d_tmp_dX+((VAK*Fmaxr)*d_Fmaxr_dX+(VAK*d_Fmaxr_dX+d_VAK_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTSTI_i_dX*(((VAK*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTSTI_i*(((VAK*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRSTI_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRSTI_i)))
{
if ((modelStruct.modelVar_PBRSTI_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)+(vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
tmp = ((((vav*modelStruct.modelVar_VBRinvsti)*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti))*(vav*modelStruct.modelVar_VBRinvsti));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvsti));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRSTI_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvsti))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRSTI_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvsti_dX+d_vav_dX*modelStruct.modelVar_VBRinvsti))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRSTI_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopsti_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.d_modelVar_slopesti_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRSTI_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
fbreakdown = (modelStruct.modelVar_fstopsti+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRSTI_i))*modelStruct.modelVar_slopesti));
}
}
d_ijunsti_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijunsti = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
if ((instanceStruct.instanceVar_LG_i==0.0))
{
d_ijungat_dX = 0.0;
ijungat = 0.0;
d_qjungat_dX = 0.0;
qjungat = 0.0;
}
else
{
if ((modelStruct.modelVar_one_minus_PGAT==0.5))
{
{
double value_sqrt_0 = sqrt((1.0-(vj*modelStruct.modelVar_vbiinvgat)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat)));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((1.0-(vj*modelStruct.modelVar_vbiinvgat)),modelStruct.modelVar_one_minus_PGAT);
double  deriv_pow_0_d0 = (((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_one_minus_PGAT/(1.0-(vj*modelStruct.modelVar_vbiinvgat))));
double  deriv_pow_0_d1 = ((1.0-(vj*modelStruct.modelVar_vbiinvgat)) == 0.0)?0.0:(log((1.0-(vj*modelStruct.modelVar_vbiinvgat)))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((-(vj*modelStruct.d_modelVar_vbiinvgat_dX+d_vj_dX*modelStruct.modelVar_vbiinvgat))))+(deriv_pow_0_d1*(modelStruct.d_modelVar_one_minus_PGAT_dX)));
tmp = value_pow_0;
}
}
d_qjungat_dX = ((modelStruct.modelVar_qprefgat*(-d_tmp_dX)+modelStruct.d_modelVar_qprefgat_dX*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(d_VAK_dX-d_vj_dX)+modelStruct.d_modelVar_qpref2gat_dX*(VAK-vj)));
qjungat = ((modelStruct.modelVar_qprefgat*(1.0-tmp))+(modelStruct.modelVar_qpref2gat*(VAK-vj)));
d_id_dX = (modelStruct.modelVar_idsatgat*d_idmult_dX+modelStruct.d_modelVar_idsatgat_dX*idmult);
id = (modelStruct.modelVar_idsatgat*idmult);
if (((modelStruct.modelVar_CSRHGAT_i==0.0)&&(modelStruct.modelVar_CTATGAT_i==0.0)))
{
d_isrh_dX = 0.0;
isrh = 0.0;
}
else
{
d_vbi_minus_vjsrh_dX = (modelStruct.d_modelVar_vbigat_dX-d_vjsrh_dX);
vbi_minus_vjsrh = (modelStruct.modelVar_vbigat-vjsrh);
{
double value_sqrt_0 = sqrt((1.0-(two_psistar/vbi_minus_vjsrh)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_wsrhstep_dX = (-deriv_sqrt_0_d0*((-((vbi_minus_vjsrh*d_two_psistar_dX-two_psistar*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh))));
wsrhstep = (1.0-value_sqrt_0);
}
if ((modelStruct.modelVar_PGAT_i==0.5))
{
d_dwsrh_dX = 0.0;
dwsrh = 0.0;
}
else
{
{
double value_log_0 = log(wsrhstep);
double  deriv_log_0_d0 = (1.0/wsrhstep);
d_dwsrh_dX = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(-2.0*modelStruct.d_modelVar_PGAT_i_dX)+((((1.0-wsrhstep)*((wsrhstep*wsrhstep)*deriv_log_0_d0*(d_wsrhstep_dX)+(wsrhstep*d_wsrhstep_dX+d_wsrhstep_dX*wsrhstep)*value_log_0)-((wsrhstep*wsrhstep)*value_log_0)*(-d_wsrhstep_dX))/(1.0-wsrhstep)/(1.0-wsrhstep))+d_wsrhstep_dX)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
dwsrh = (((((wsrhstep*wsrhstep)*value_log_0)/(1.0-wsrhstep))+wsrhstep)*(1.0-(2.0*modelStruct.modelVar_PGAT_i)));
}
}
d_wsrh_dX = (d_wsrhstep_dX+d_dwsrh_dX);
wsrh = (wsrhstep+dwsrh);
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = (((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/(vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = ((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log((vbi_minus_vjsrh*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*((vbi_minus_vjsrh*modelStruct.d_modelVar_VBIRGATinv_dX+d_vbi_minus_vjsrh_dX*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_wdep_dX = (modelStruct.modelVar_wdepnulrgat*d_tmp_dX+modelStruct.d_modelVar_wdepnulrgat_dX*tmp);
wdep = (modelStruct.modelVar_wdepnulrgat*tmp);
d_asrh_dX = (modelStruct.modelVar_ftdgat*((zinv-1.0)*d_wdep_dX+d_zinv_dX*wdep)+modelStruct.d_modelVar_ftdgat_dX*((zinv-1.0)*wdep));
asrh = (modelStruct.modelVar_ftdgat*((zinv-1.0)*wdep));
d_isrh_dX = (modelStruct.modelVar_CSRHGAT_i*(asrh*d_wsrh_dX+d_asrh_dX*wsrh)+modelStruct.d_modelVar_CSRHGAT_i_dX*(asrh*wsrh));
isrh = (modelStruct.modelVar_CSRHGAT_i*(asrh*wsrh));
}
if ((modelStruct.modelVar_CTATGAT_i==0.0))
{
d_itat_dX = 0.0;
itat = 0.0;
}
else
{
d_btat_dX = (modelStruct.modelVar_btatpartgat*((vbi_minus_vjsrh*(wdep*modelStruct.d_modelVar_one_minus_PGAT_dX+d_wdep_dX*modelStruct.modelVar_one_minus_PGAT)-(wdep*modelStruct.modelVar_one_minus_PGAT)*d_vbi_minus_vjsrh_dX)/vbi_minus_vjsrh/vbi_minus_vjsrh)+modelStruct.d_modelVar_btatpartgat_dX*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
btat = (modelStruct.modelVar_btatpartgat*((wdep*modelStruct.modelVar_one_minus_PGAT)/vbi_minus_vjsrh));
d_twoatatoverthreebtat_dX = ((btat*0.666666666666667*modelStruct.d_modelVar_atatgat_dX-(0.666666666666667*modelStruct.modelVar_atatgat)*d_btat_dX)/btat/btat);
twoatatoverthreebtat = ((0.666666666666667*modelStruct.modelVar_atatgat)/btat);
d_umaxbeforelimiting_dX = (twoatatoverthreebtat*d_twoatatoverthreebtat_dX+d_twoatatoverthreebtat_dX*twoatatoverthreebtat);
umaxbeforelimiting = (twoatatoverthreebtat*twoatatoverthreebtat);
{
double value_sqrt_0 = sqrt(((umaxbeforelimiting*umaxbeforelimiting)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_umax_dX = deriv_sqrt_0_d0*(((((umaxbeforelimiting*umaxbeforelimiting)+1.0)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting)-(umaxbeforelimiting*umaxbeforelimiting)*(umaxbeforelimiting*d_umaxbeforelimiting_dX+d_umaxbeforelimiting_dX*umaxbeforelimiting))/((umaxbeforelimiting*umaxbeforelimiting)+1.0)/((umaxbeforelimiting*umaxbeforelimiting)+1.0)));
umax = value_sqrt_0;
}
{
double value_fabs_0 = fabs(umax);
double value_sqrt_1 = sqrt(value_fabs_0);
double  deriv_fabs_0_d0 = (((umax)>=0)?(+1.0):(-1.0));
double  deriv_sqrt_1_d0 = (0.5/value_sqrt_1);
d_sqrtumax_dX = deriv_sqrt_1_d0*(deriv_fabs_0_d0*(d_umax_dX));
sqrtumax = value_sqrt_1;
}
d_umaxpoweronepointfive_dX = (umax*d_sqrtumax_dX+d_umax_dX*sqrtumax);
umaxpoweronepointfive = (umax*sqrtumax);
if ((((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)==(-1.0)))
{
d_wgamma_dX = (-(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)/(1.0+(btat*umaxpoweronepointfive))/(1.0+(btat*umaxpoweronepointfive)));
wgamma = (1.0/(1.0+(btat*umaxpoweronepointfive)));
}
else
{
{
double value_pow_0 = pow((1.0+(btat*umaxpoweronepointfive)),((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT));
double  deriv_pow_0_d0 = (((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(value_pow_0*((-modelStruct.modelVar_PGAT_i)*modelStruct.modelVar_one_over_one_minus_PGAT)/(1.0+(btat*umaxpoweronepointfive))));
double  deriv_pow_0_d1 = ((1.0+(btat*umaxpoweronepointfive)) == 0.0)?0.0:(log((1.0+(btat*umaxpoweronepointfive)))*value_pow_0);
d_wgamma_dX = ((deriv_pow_0_d0*((btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive)))+(deriv_pow_0_d1*(((-modelStruct.modelVar_PGAT_i)*modelStruct.d_modelVar_one_over_one_minus_PGAT_dX+(-modelStruct.d_modelVar_PGAT_i_dX)*modelStruct.modelVar_one_over_one_minus_PGAT))));
wgamma = value_pow_0;
}
}
d_wtat_dX = (((wsrh+wgamma)*(wsrh*d_wgamma_dX+d_wsrh_dX*wgamma)-(wsrh*wgamma)*(d_wsrh_dX+d_wgamma_dX))/(wsrh+wgamma)/(wsrh+wgamma));
wtat = ((wsrh*wgamma)/(wsrh+wgamma));
{
double value_sqrt_0 = sqrt((0.375*(btat/sqrtumax)));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_ktat_dX = deriv_sqrt_0_d0*(0.375*((sqrtumax*d_btat_dX-btat*d_sqrtumax_dX)/sqrtumax/sqrtumax));
ktat = value_sqrt_0;
}
d_ltat_dX = (2.0*(twoatatoverthreebtat*d_sqrtumax_dX+d_twoatatoverthreebtat_dX*sqrtumax)-d_umax_dX);
ltat = ((2.0*(twoatatoverthreebtat*sqrtumax))-umax);
d_mtat_dX = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*d_sqrtumax_dX+(modelStruct.modelVar_atatgat*d_twoatatoverthreebtat_dX+modelStruct.d_modelVar_atatgat_dX*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*d_umax_dX+modelStruct.d_modelVar_atatgat_dX*umax))+0.5*(btat*d_umaxpoweronepointfive_dX+d_btat_dX*umaxpoweronepointfive));
mtat = ((((modelStruct.modelVar_atatgat*twoatatoverthreebtat)*sqrtumax)-(modelStruct.modelVar_atatgat*umax))+(0.5*(btat*umaxpoweronepointfive)));
d_xerfc_dX = ((ltat-1.0)*d_ktat_dX+d_ltat_dX*ktat);
xerfc = ((ltat-1.0)*ktat);
d_ysq_dX = (xerfc*d_xerfc_dX+d_xerfc_dX*xerfc);
ysq = (xerfc*xerfc);
if ((xerfc>0.0))
{
d_terfc_dX = (-modelStruct.modelVar_perfc*d_xerfc_dX/(1.0+(modelStruct.modelVar_perfc*xerfc))/(1.0+(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0+(modelStruct.modelVar_perfc*xerfc)));
}
else
{
d_terfc_dX = (-(-modelStruct.modelVar_perfc*d_xerfc_dX)/(1.0-(modelStruct.modelVar_perfc*xerfc))/(1.0-(modelStruct.modelVar_perfc*xerfc)));
terfc = (1.0/(1.0-(modelStruct.modelVar_perfc*xerfc)));
}
if ((((-ysq)+mtat)>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(((-ysq)+mtat));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((-d_ysq_dX)+d_mtat_dX));
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-ysq)+mtat))*0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(-((-d_ysq_dX)+d_mtat_dX))*3.3333333333333333e-01+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))+(-((-d_ysq_dX)+d_mtat_dX))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-ysq)+mtat))*(1.0+(((-2.3025850929940458e+02)-((-ysq)+mtat))*3.3333333333333333e-01))))))));
}
d_erfcpos_dX = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*d_tmp_dX+((0.29214664*d_terfc_dX+modelStruct.modelVar_berfc*(terfc*d_terfc_dX+d_terfc_dX*terfc))+modelStruct.modelVar_cerfc*((terfc*terfc)*d_terfc_dX+(terfc*d_terfc_dX+d_terfc_dX*terfc)*terfc))*tmp);
erfcpos = ((((0.29214664*terfc)+(modelStruct.modelVar_berfc*(terfc*terfc)))+(modelStruct.modelVar_cerfc*((terfc*terfc)*terfc)))*tmp);
if ((xerfc>0.0))
{
d_erfctimesexpmtat_dX = d_erfcpos_dX;
erfctimesexpmtat = erfcpos;
}
else
{
if ((mtat>(-2.3025850929940458e+02)))
{
{
double value_exp_0 = exp(mtat);
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(d_mtat_dX);
tmp = value_exp_0;
}
}
else
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-mtat)*0.5*(((-2.3025850929940458e+02)-mtat)*(-d_mtat_dX)*3.3333333333333333e-01+(-d_mtat_dX)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))+(-d_mtat_dX)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-mtat)*(1.0+(0.5*(((-2.3025850929940458e+02)-mtat)*(1.0+(((-2.3025850929940458e+02)-mtat)*3.3333333333333333e-01))))))));
}
d_erfctimesexpmtat_dX = (2.0*d_tmp_dX-d_erfcpos_dX);
erfctimesexpmtat = ((2.0*tmp)-erfcpos);
}
d_gammamax_dX = (1.77245385090551603*0.5)*((ktat*(modelStruct.modelVar_atatgat*d_erfctimesexpmtat_dX+modelStruct.d_modelVar_atatgat_dX*erfctimesexpmtat)-(modelStruct.modelVar_atatgat*erfctimesexpmtat)*d_ktat_dX)/ktat/ktat);
gammamax = ((1.77245385090551603*0.5)*((modelStruct.modelVar_atatgat*erfctimesexpmtat)/ktat));
d_itat_dX = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*d_wtat_dX+(asrh*d_gammamax_dX+d_asrh_dX*gammamax)*wtat)+modelStruct.d_modelVar_CTATGAT_i_dX*((asrh*gammamax)*wtat));
itat = (modelStruct.modelVar_CTATGAT_i*((asrh*gammamax)*wtat));
}
if ((modelStruct.modelVar_CBBTGAT_i==0.0))
{
d_ibbt_dX = 0.0;
ibbt = 0.0;
}
else
{
if ((modelStruct.modelVar_PGAT_i==0.5))
{
{
double value_sqrt_0 = sqrt(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv));
double  deriv_sqrt_0_d0 = (0.5/value_sqrt_0);
d_tmp_dX = deriv_sqrt_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv));
tmp = value_sqrt_0;
}
}
else
{
{
double value_pow_0 = pow(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv),modelStruct.modelVar_PGAT_i);
double  deriv_pow_0_d0 = ((((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(value_pow_0*modelStruct.modelVar_PGAT_i/((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv)));
double  deriv_pow_0_d1 = (((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv) == 0.0)?0.0:(log(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_VBIRGATinv))*value_pow_0);
d_tmp_dX = ((deriv_pow_0_d0*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_VBIRGATinv_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_VBIRGATinv)))+(deriv_pow_0_d1*(modelStruct.d_modelVar_PGAT_i_dX)));
tmp = value_pow_0;
}
}
d_Fmaxr_dX = (modelStruct.modelVar_one_over_one_minus_PGAT*((tmp*((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.d_modelVar_wdepnulrinvgat_dX+(modelStruct.d_modelVar_VBIRGAT_i_dX-d_vbbt_dX)*modelStruct.modelVar_wdepnulrinvgat)-((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)*d_tmp_dX)/tmp/tmp)+modelStruct.d_modelVar_one_over_one_minus_PGAT_dX*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
Fmaxr = (modelStruct.modelVar_one_over_one_minus_PGAT*(((modelStruct.modelVar_VBIRGAT_i-vbbt)*modelStruct.modelVar_wdepnulrinvgat)/tmp));
if ((fabs(((-modelStruct.modelVar_fbbtgat)/Fmaxr))<2.3025850929940458e+02))
{
{
double value_exp_0 = exp(((-modelStruct.modelVar_fbbtgat)/Fmaxr));
double  deriv_exp_0_d0 = value_exp_0;
d_tmp_dX = deriv_exp_0_d0*(((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr));
tmp = value_exp_0;
}
}
else
{
if ((((-modelStruct.modelVar_fbbtgat)/Fmaxr)<0.0))
{
d_tmp_dX = (-1.0e-100*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*3.3333333333333333e-01+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))+(-((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01)))))))/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
tmp = (1.0e-100/(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(0.5*(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*(1.0+(((-2.3025850929940458e+02)-((-modelStruct.modelVar_fbbtgat)/Fmaxr))*3.3333333333333333e-01))))))));
}
else
{
d_tmp_dX = 1.0e100*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*3.3333333333333333e-01+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01)))+((Fmaxr*(-modelStruct.d_modelVar_fbbtgat_dX)-(-modelStruct.modelVar_fbbtgat)*d_Fmaxr_dX)/Fmaxr/Fmaxr)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))));
tmp = (1.0e100*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+(0.5*((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*(1.0+((((-modelStruct.modelVar_fbbtgat)/Fmaxr)-2.3025850929940458e+02)*3.3333333333333333e-01))))))));
}
}
d_ibbt_dX = (modelStruct.modelVar_CBBTGAT_i*(((VAK*Fmaxr)*Fmaxr)*d_tmp_dX+((VAK*Fmaxr)*d_Fmaxr_dX+(VAK*d_Fmaxr_dX+d_VAK_dX*Fmaxr)*Fmaxr)*tmp)+modelStruct.d_modelVar_CBBTGAT_i_dX*(((VAK*Fmaxr)*Fmaxr)*tmp));
ibbt = (modelStruct.modelVar_CBBTGAT_i*(((VAK*Fmaxr)*Fmaxr)*tmp));
}
if ((modelStruct.modelVar_VBRGAT_i>1.0e3))
{
d_fbreakdown_dX = 0.0;
fbreakdown = 1.0;
}
else
{
if ((vav>((-modelStruct.modelVar_alphaav)*modelStruct.modelVar_VBRGAT_i)))
{
if ((modelStruct.modelVar_PBRGAT_i==4.0))
{
d_tmp_dX = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)+(vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
tmp = ((((vav*modelStruct.modelVar_VBRinvgat)*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat))*(vav*modelStruct.modelVar_VBRinvgat));
}
else
{
{
double value_fabs_0 = fabs((vav*modelStruct.modelVar_VBRinvgat));
double value_pow_1 = pow(value_fabs_0,modelStruct.modelVar_PBRGAT_i);
double  deriv_fabs_0_d0 = ((((vav*modelStruct.modelVar_VBRinvgat))>=0)?(+1.0):(-1.0));
double  deriv_pow_1_d0 = ((value_fabs_0 == 0.0)?0.0:(value_pow_1*modelStruct.modelVar_PBRGAT_i/value_fabs_0));
double  deriv_pow_1_d1 = (value_fabs_0 == 0.0)?0.0:(log(value_fabs_0)*value_pow_1);
d_tmp_dX = ((deriv_pow_1_d0*(deriv_fabs_0_d0*((vav*modelStruct.d_modelVar_VBRinvgat_dX+d_vav_dX*modelStruct.modelVar_VBRinvgat))))+(deriv_pow_1_d1*(modelStruct.d_modelVar_PBRGAT_i_dX)));
tmp = value_pow_1;
}
}
d_fbreakdown_dX = (-(-d_tmp_dX)/(1.0-tmp)/(1.0-tmp));
fbreakdown = (1.0/(1.0-tmp));
}
else
{
d_fbreakdown_dX = (modelStruct.d_modelVar_fstopgat_dX+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.d_modelVar_slopegat_dX+(d_vav_dX+(modelStruct.modelVar_alphaav*modelStruct.d_modelVar_VBRGAT_i_dX+modelStruct.d_modelVar_alphaav_dX*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
fbreakdown = (modelStruct.modelVar_fstopgat+((vav+(modelStruct.modelVar_alphaav*modelStruct.modelVar_VBRGAT_i))*modelStruct.modelVar_slopegat));
}
}
d_ijungat_dX = ((((id+isrh)+itat)+ibbt)*d_fbreakdown_dX+(((d_id_dX+d_isrh_dX)+d_itat_dX)+d_ibbt_dX)*fbreakdown);
ijungat = ((((id+isrh)+itat)+ibbt)*fbreakdown);
}
d_ijun_dX = (((instanceStruct.instanceVar_AB_i*d_ijunbot_dX+instanceStruct.d_instanceVar_AB_i_dX*ijunbot)+(instanceStruct.instanceVar_LS_i*d_ijunsti_dX+instanceStruct.d_instanceVar_LS_i_dX*ijunsti))+(instanceStruct.instanceVar_LG_i*d_ijungat_dX+instanceStruct.d_instanceVar_LG_i_dX*ijungat));
ijun = (((instanceStruct.instanceVar_AB_i*ijunbot)+(instanceStruct.instanceVar_LS_i*ijunsti))+(instanceStruct.instanceVar_LG_i*ijungat));
}
d_qjun_dX = (((instanceStruct.instanceVar_AB_i*d_qjunbot_dX+instanceStruct.d_instanceVar_AB_i_dX*qjunbot)+(instanceStruct.instanceVar_LS_i*d_qjunsti_dX+instanceStruct.d_instanceVar_LS_i_dX*qjunsti))+(instanceStruct.instanceVar_LG_i*d_qjungat_dX+instanceStruct.d_instanceVar_LG_i_dX*qjungat));
qjun = (((instanceStruct.instanceVar_AB_i*qjunbot)+(instanceStruct.instanceVar_LS_i*qjunsti))+(instanceStruct.instanceVar_LG_i*qjungat));
}
// End block evaluateStaticDynamic
//Begin block loadStatic
{
// I(A,K) <+ (((TYPE*MULT_i)*ijun))
d_staticContributions_dX[admsNodeID_A]+= ((modelStruct.modelPar_TYPE*instanceStruct.instanceVar_MULT_i)*d_ijun_dX+modelStruct.modelPar_TYPE*instanceStruct.d_instanceVar_MULT_i_dX*ijun);
d_staticContributions_dX[(admsNodeID_K)]-= ((modelStruct.modelPar_TYPE*instanceStruct.instanceVar_MULT_i)*d_ijun_dX+modelStruct.modelPar_TYPE*instanceStruct.d_instanceVar_MULT_i_dX*ijun);
}
// End block loadStatic
//Begin block loadDynamic
{
// I(A,K) <+ (ddt(((TYPE*MULT_i)*qjun)))
d_dynamicContributions_dX[admsNodeID_A]+= (((modelStruct.modelPar_TYPE*instanceStruct.instanceVar_MULT_i)*d_qjun_dX+modelStruct.modelPar_TYPE*instanceStruct.d_instanceVar_MULT_i_dX*qjun));
d_dynamicContributions_dX[(admsNodeID_K)]-= (((modelStruct.modelPar_TYPE*instanceStruct.instanceVar_MULT_i)*d_qjun_dX+modelStruct.modelPar_TYPE*instanceStruct.d_instanceVar_MULT_i_dX*qjun));
}
// End block loadDynamic
//Begin block noise
{
{
double value_fabs_0 = fabs(ijun);
double  deriv_fabs_0_d0 = (((ijun)>=0)?(+1.0):(-1.0));
d_jnoise_dX = (2*1.6021918E-19)*deriv_fabs_0_d0*(d_ijun_dX);
jnoise = ((2*1.6021918E-19)*value_fabs_0);
}
// I(A,K) <+ (white_noise((MULT_i*jnoise),"shot"))
}
// End block noise
//Begin block OPinfo
{
if ((modelStruct.modelVar_SWJUNEXP_i==1.0))
{
}
else
{
}
}
// End block OPinfo
}
// End block evaluateblock
}



//-----------------------------------------------------------------------------
// Function      : InstanceSensitivity::operator()
// Purpose       : return sensitivity for a single instance parameter
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
/// Compute sensitivity of a device instance's outputs to a specified instance
/// parameter
///
///
/// @param[in] entity  The device entity that owns the parameter
/// @param[in] name    The unadorned parameter name specific to the entity
/// @param[out] dfdp   The derivative of the F vector with respect to the parameter
/// @param[out] dqdp   The derivative of the Q vector with respect to the parameter
/// @param[out] dbdp   The derivative of the B vector with respect to the parameter
/// @param[out] Findices   The indices into the F vector corresponding to the elements of dfdp
/// @param[out] Qindices   The indices into the Q vector corresponding to the elements of dfdp
/// @param[out] Bindices   The indices into the B vector corresponding to the elements of dfdp
///
///
void InstanceSensitivity::operator()
(
const ParameterBase &entity,
const std::string &name,
std::vector<double> & dfdp,
std::vector<double> & dqdp,
std::vector<double> & dbdp,
std::vector<int> & Findices,
std::vector<int> & Qindices,
std::vector<int> & Bindices
) const
{
const ParameterBase * e1 = &entity;
const Instance & in = *(dynamic_cast<const Instance *> (e1));
const Model & mod =in.model_;

dfdp.resize(2+0);
dqdp.resize(2+0);
Findices.resize(2+0);
Qindices.resize(2+0);

std::vector <double> probeVars(2);
std::vector <double> d_staticContributions_dX(2+0);
std::vector <double> d_dynamicContributions_dX(2+0);


// initialize contributions to zero (automatically sets derivatives to zero)
for (int i=0; i < 2+0 ; ++i)
{
   d_staticContributions_dX[i]=0;
   d_dynamicContributions_dX[i]=0;
}

// Copy out all the model parameters (doubles) into local structure
modelSensStruct modelStruct;

//reals
modelStruct.modelPar_DTA=mod.DTA;
modelStruct.d_modelPar_DTA_dX=0.0;
modelStruct.modelPar_given_DTA=mod.given("DTA");
modelStruct.modelPar_IMAX=mod.IMAX;
modelStruct.d_modelPar_IMAX_dX=0.0;
modelStruct.modelPar_given_IMAX=mod.given("IMAX");
modelStruct.modelPar_TRJ=mod.TRJ;
modelStruct.d_modelPar_TRJ_dX=0.0;
modelStruct.modelPar_given_TRJ=mod.given("TRJ");
modelStruct.modelPar_FREV=mod.FREV;
modelStruct.d_modelPar_FREV_dX=0.0;
modelStruct.modelPar_given_FREV=mod.given("FREV");
modelStruct.modelPar_CJORBOT=mod.CJORBOT;
modelStruct.d_modelPar_CJORBOT_dX=0.0;
modelStruct.modelPar_given_CJORBOT=mod.given("CJORBOT");
modelStruct.modelPar_CJORSTI=mod.CJORSTI;
modelStruct.d_modelPar_CJORSTI_dX=0.0;
modelStruct.modelPar_given_CJORSTI=mod.given("CJORSTI");
modelStruct.modelPar_CJORGAT=mod.CJORGAT;
modelStruct.d_modelPar_CJORGAT_dX=0.0;
modelStruct.modelPar_given_CJORGAT=mod.given("CJORGAT");
modelStruct.modelPar_VBIRBOT=mod.VBIRBOT;
modelStruct.d_modelPar_VBIRBOT_dX=0.0;
modelStruct.modelPar_given_VBIRBOT=mod.given("VBIRBOT");
modelStruct.modelPar_VBIRSTI=mod.VBIRSTI;
modelStruct.d_modelPar_VBIRSTI_dX=0.0;
modelStruct.modelPar_given_VBIRSTI=mod.given("VBIRSTI");
modelStruct.modelPar_VBIRGAT=mod.VBIRGAT;
modelStruct.d_modelPar_VBIRGAT_dX=0.0;
modelStruct.modelPar_given_VBIRGAT=mod.given("VBIRGAT");
modelStruct.modelPar_PBOT=mod.PBOT;
modelStruct.d_modelPar_PBOT_dX=0.0;
modelStruct.modelPar_given_PBOT=mod.given("PBOT");
modelStruct.modelPar_PSTI=mod.PSTI;
modelStruct.d_modelPar_PSTI_dX=0.0;
modelStruct.modelPar_given_PSTI=mod.given("PSTI");
modelStruct.modelPar_PGAT=mod.PGAT;
modelStruct.d_modelPar_PGAT_dX=0.0;
modelStruct.modelPar_given_PGAT=mod.given("PGAT");
modelStruct.modelPar_PHIGBOT=mod.PHIGBOT;
modelStruct.d_modelPar_PHIGBOT_dX=0.0;
modelStruct.modelPar_given_PHIGBOT=mod.given("PHIGBOT");
modelStruct.modelPar_PHIGSTI=mod.PHIGSTI;
modelStruct.d_modelPar_PHIGSTI_dX=0.0;
modelStruct.modelPar_given_PHIGSTI=mod.given("PHIGSTI");
modelStruct.modelPar_PHIGGAT=mod.PHIGGAT;
modelStruct.d_modelPar_PHIGGAT_dX=0.0;
modelStruct.modelPar_given_PHIGGAT=mod.given("PHIGGAT");
modelStruct.modelPar_IDSATRBOT=mod.IDSATRBOT;
modelStruct.d_modelPar_IDSATRBOT_dX=0.0;
modelStruct.modelPar_given_IDSATRBOT=mod.given("IDSATRBOT");
modelStruct.modelPar_IDSATRSTI=mod.IDSATRSTI;
modelStruct.d_modelPar_IDSATRSTI_dX=0.0;
modelStruct.modelPar_given_IDSATRSTI=mod.given("IDSATRSTI");
modelStruct.modelPar_IDSATRGAT=mod.IDSATRGAT;
modelStruct.d_modelPar_IDSATRGAT_dX=0.0;
modelStruct.modelPar_given_IDSATRGAT=mod.given("IDSATRGAT");
modelStruct.modelPar_CSRHBOT=mod.CSRHBOT;
modelStruct.d_modelPar_CSRHBOT_dX=0.0;
modelStruct.modelPar_given_CSRHBOT=mod.given("CSRHBOT");
modelStruct.modelPar_CSRHSTI=mod.CSRHSTI;
modelStruct.d_modelPar_CSRHSTI_dX=0.0;
modelStruct.modelPar_given_CSRHSTI=mod.given("CSRHSTI");
modelStruct.modelPar_CSRHGAT=mod.CSRHGAT;
modelStruct.d_modelPar_CSRHGAT_dX=0.0;
modelStruct.modelPar_given_CSRHGAT=mod.given("CSRHGAT");
modelStruct.modelPar_XJUNSTI=mod.XJUNSTI;
modelStruct.d_modelPar_XJUNSTI_dX=0.0;
modelStruct.modelPar_given_XJUNSTI=mod.given("XJUNSTI");
modelStruct.modelPar_XJUNGAT=mod.XJUNGAT;
modelStruct.d_modelPar_XJUNGAT_dX=0.0;
modelStruct.modelPar_given_XJUNGAT=mod.given("XJUNGAT");
modelStruct.modelPar_CTATBOT=mod.CTATBOT;
modelStruct.d_modelPar_CTATBOT_dX=0.0;
modelStruct.modelPar_given_CTATBOT=mod.given("CTATBOT");
modelStruct.modelPar_CTATSTI=mod.CTATSTI;
modelStruct.d_modelPar_CTATSTI_dX=0.0;
modelStruct.modelPar_given_CTATSTI=mod.given("CTATSTI");
modelStruct.modelPar_CTATGAT=mod.CTATGAT;
modelStruct.d_modelPar_CTATGAT_dX=0.0;
modelStruct.modelPar_given_CTATGAT=mod.given("CTATGAT");
modelStruct.modelPar_MEFFTATBOT=mod.MEFFTATBOT;
modelStruct.d_modelPar_MEFFTATBOT_dX=0.0;
modelStruct.modelPar_given_MEFFTATBOT=mod.given("MEFFTATBOT");
modelStruct.modelPar_MEFFTATSTI=mod.MEFFTATSTI;
modelStruct.d_modelPar_MEFFTATSTI_dX=0.0;
modelStruct.modelPar_given_MEFFTATSTI=mod.given("MEFFTATSTI");
modelStruct.modelPar_MEFFTATGAT=mod.MEFFTATGAT;
modelStruct.d_modelPar_MEFFTATGAT_dX=0.0;
modelStruct.modelPar_given_MEFFTATGAT=mod.given("MEFFTATGAT");
modelStruct.modelPar_CBBTBOT=mod.CBBTBOT;
modelStruct.d_modelPar_CBBTBOT_dX=0.0;
modelStruct.modelPar_given_CBBTBOT=mod.given("CBBTBOT");
modelStruct.modelPar_CBBTSTI=mod.CBBTSTI;
modelStruct.d_modelPar_CBBTSTI_dX=0.0;
modelStruct.modelPar_given_CBBTSTI=mod.given("CBBTSTI");
modelStruct.modelPar_CBBTGAT=mod.CBBTGAT;
modelStruct.d_modelPar_CBBTGAT_dX=0.0;
modelStruct.modelPar_given_CBBTGAT=mod.given("CBBTGAT");
modelStruct.modelPar_FBBTRBOT=mod.FBBTRBOT;
modelStruct.d_modelPar_FBBTRBOT_dX=0.0;
modelStruct.modelPar_given_FBBTRBOT=mod.given("FBBTRBOT");
modelStruct.modelPar_FBBTRSTI=mod.FBBTRSTI;
modelStruct.d_modelPar_FBBTRSTI_dX=0.0;
modelStruct.modelPar_given_FBBTRSTI=mod.given("FBBTRSTI");
modelStruct.modelPar_FBBTRGAT=mod.FBBTRGAT;
modelStruct.d_modelPar_FBBTRGAT_dX=0.0;
modelStruct.modelPar_given_FBBTRGAT=mod.given("FBBTRGAT");
modelStruct.modelPar_STFBBTBOT=mod.STFBBTBOT;
modelStruct.d_modelPar_STFBBTBOT_dX=0.0;
modelStruct.modelPar_given_STFBBTBOT=mod.given("STFBBTBOT");
modelStruct.modelPar_STFBBTSTI=mod.STFBBTSTI;
modelStruct.d_modelPar_STFBBTSTI_dX=0.0;
modelStruct.modelPar_given_STFBBTSTI=mod.given("STFBBTSTI");
modelStruct.modelPar_STFBBTGAT=mod.STFBBTGAT;
modelStruct.d_modelPar_STFBBTGAT_dX=0.0;
modelStruct.modelPar_given_STFBBTGAT=mod.given("STFBBTGAT");
modelStruct.modelPar_VBRBOT=mod.VBRBOT;
modelStruct.d_modelPar_VBRBOT_dX=0.0;
modelStruct.modelPar_given_VBRBOT=mod.given("VBRBOT");
modelStruct.modelPar_VBRSTI=mod.VBRSTI;
modelStruct.d_modelPar_VBRSTI_dX=0.0;
modelStruct.modelPar_given_VBRSTI=mod.given("VBRSTI");
modelStruct.modelPar_VBRGAT=mod.VBRGAT;
modelStruct.d_modelPar_VBRGAT_dX=0.0;
modelStruct.modelPar_given_VBRGAT=mod.given("VBRGAT");
modelStruct.modelPar_PBRBOT=mod.PBRBOT;
modelStruct.d_modelPar_PBRBOT_dX=0.0;
modelStruct.modelPar_given_PBRBOT=mod.given("PBRBOT");
modelStruct.modelPar_PBRSTI=mod.PBRSTI;
modelStruct.d_modelPar_PBRSTI_dX=0.0;
modelStruct.modelPar_given_PBRSTI=mod.given("PBRSTI");
modelStruct.modelPar_PBRGAT=mod.PBRGAT;
modelStruct.d_modelPar_PBRGAT_dX=0.0;
modelStruct.modelPar_given_PBRGAT=mod.given("PBRGAT");
modelStruct.modelPar_SWJUNEXP=mod.SWJUNEXP;
modelStruct.d_modelPar_SWJUNEXP_dX=0.0;
modelStruct.modelPar_given_SWJUNEXP=mod.given("SWJUNEXP");
modelStruct.modelPar_VJUNREF=mod.VJUNREF;
modelStruct.d_modelPar_VJUNREF_dX=0.0;
modelStruct.modelPar_given_VJUNREF=mod.given("VJUNREF");
modelStruct.modelPar_FJUNQ=mod.FJUNQ;
modelStruct.d_modelPar_FJUNQ_dX=0.0;
modelStruct.modelPar_given_FJUNQ=mod.given("FJUNQ");


// hidden reals


// non-reals (including hiddens)
modelStruct.modelPar_LEVEL=mod.LEVEL;
modelStruct.modelPar_given_LEVEL=mod.given("LEVEL");
modelStruct.modelPar_TYPE=mod.TYPE;
modelStruct.modelPar_given_TYPE=mod.given("TYPE");



// Copy out all the instance parameters (doubles) into local struct
// Keep a map so we can set the right one to the independent variable
// We do this solely to avoid a big ugly "if/else" block just to find the
// one parameter we're doing sensitivities on.
unordered_map <std::string,double*,HashNoCase,EqualNoCase> inParamMap;
instanceSensStruct instanceStruct;
// reals
instanceStruct.instancePar_AB=in.AB;
instanceStruct.d_instancePar_AB_dX=0.0;
instanceStruct.instancePar_given_AB=in.given("AB");
inParamMap["AB"] = &(instanceStruct.d_instancePar_AB_dX);
instanceStruct.instancePar_LS=in.LS;
instanceStruct.d_instancePar_LS_dX=0.0;
instanceStruct.instancePar_given_LS=in.given("LS");
inParamMap["LS"] = &(instanceStruct.d_instancePar_LS_dX);
instanceStruct.instancePar_LG=in.LG;
instanceStruct.d_instancePar_LG_dX=0.0;
instanceStruct.instancePar_given_LG=in.given("LG");
inParamMap["LG"] = &(instanceStruct.d_instancePar_LG_dX);
instanceStruct.instancePar_MULT=in.MULT;
instanceStruct.d_instancePar_MULT_dX=0.0;
instanceStruct.instancePar_given_MULT=in.given("MULT");
inParamMap["MULT"] = &(instanceStruct.d_instancePar_MULT_dX);


// Copy all the real hidden instance params into local struct



// Copy all the non-real instance params into vars of their appropriate type:


// Set the one parameter whose name was passed in to be the independent
// variable for differentiation purposes.  Since we stored variable pointers, this
// makes sure that that ONE variable gets set right.
// FIXME: make this check the name first, otherwise segfault on invalid name!
*(inParamMap[name])=1.0;

//make local copies of all instance vars
//reals
instanceStruct.instanceVar_MULT_i=in.MULT_i;
instanceStruct.d_instanceVar_MULT_i_dX=0.0;
instanceStruct.instanceVar_AB_i=in.AB_i;
instanceStruct.d_instanceVar_AB_i_dX=0.0;
instanceStruct.instanceVar_LS_i=in.LS_i;
instanceStruct.d_instanceVar_LS_i_dX=0.0;
instanceStruct.instanceVar_LG_i=in.LG_i;
instanceStruct.d_instanceVar_LG_i_dX=0.0;
instanceStruct.instanceVar_zflagbot=in.zflagbot;
instanceStruct.instanceVar_zflagsti=in.zflagsti;
instanceStruct.instanceVar_zflaggat=in.zflaggat;
instanceStruct.instanceVar_VMAX=in.VMAX;
instanceStruct.d_instanceVar_VMAX_dX=0.0;
instanceStruct.instanceVar_exp_VMAX_over_phitd=in.exp_VMAX_over_phitd;
instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX=0.0;
instanceStruct.instanceVar_vbimin=in.vbimin;
instanceStruct.d_instanceVar_vbimin_dX=0.0;
instanceStruct.instanceVar_vch=in.vch;
instanceStruct.d_instanceVar_vch_dX=0.0;
instanceStruct.instanceVar_vfmin=in.vfmin;
instanceStruct.d_instanceVar_vfmin_dX=0.0;
instanceStruct.instanceVar_vbbtlim=in.vbbtlim;
instanceStruct.d_instanceVar_vbbtlim_dX=0.0;
instanceStruct.instanceVar_xhighf1=in.xhighf1;
instanceStruct.d_instanceVar_xhighf1_dX=0.0;
instanceStruct.instanceVar_expxhf1=in.expxhf1;
instanceStruct.d_instanceVar_expxhf1_dX=0.0;
instanceStruct.instanceVar_xhighf2=in.xhighf2;
instanceStruct.d_instanceVar_xhighf2_dX=0.0;
instanceStruct.instanceVar_expxhf2=in.expxhf2;
instanceStruct.d_instanceVar_expxhf2_dX=0.0;
instanceStruct.instanceVar_xhighr=in.xhighr;
instanceStruct.d_instanceVar_xhighr_dX=0.0;
instanceStruct.instanceVar_expxhr=in.expxhr;
instanceStruct.d_instanceVar_expxhr_dX=0.0;
instanceStruct.instanceVar_ISATFOR1=in.ISATFOR1;
instanceStruct.d_instanceVar_ISATFOR1_dX=0.0;
instanceStruct.instanceVar_MFOR1=in.MFOR1;
instanceStruct.instanceVar_ISATFOR2=in.ISATFOR2;
instanceStruct.d_instanceVar_ISATFOR2_dX=0.0;
instanceStruct.instanceVar_MFOR2=in.MFOR2;
instanceStruct.d_instanceVar_MFOR2_dX=0.0;
instanceStruct.instanceVar_ISATREV=in.ISATREV;
instanceStruct.d_instanceVar_ISATREV_dX=0.0;
instanceStruct.instanceVar_MREV=in.MREV;
instanceStruct.d_instanceVar_MREV_dX=0.0;
instanceStruct.instanceVar_m0flag=in.m0flag;


//non-reals


//make local copies of all model vars
//reals
modelStruct.modelVar_IMAX_i=mod.IMAX_i;
modelStruct.d_modelVar_IMAX_i_dX=0.0;
modelStruct.modelVar_VBIRBOT_i=mod.VBIRBOT_i;
modelStruct.d_modelVar_VBIRBOT_i_dX=0.0;
modelStruct.modelVar_VBIRSTI_i=mod.VBIRSTI_i;
modelStruct.d_modelVar_VBIRSTI_i_dX=0.0;
modelStruct.modelVar_VBIRGAT_i=mod.VBIRGAT_i;
modelStruct.d_modelVar_VBIRGAT_i_dX=0.0;
modelStruct.modelVar_PBOT_i=mod.PBOT_i;
modelStruct.d_modelVar_PBOT_i_dX=0.0;
modelStruct.modelVar_PSTI_i=mod.PSTI_i;
modelStruct.d_modelVar_PSTI_i_dX=0.0;
modelStruct.modelVar_PGAT_i=mod.PGAT_i;
modelStruct.d_modelVar_PGAT_i_dX=0.0;
modelStruct.modelVar_CSRHBOT_i=mod.CSRHBOT_i;
modelStruct.d_modelVar_CSRHBOT_i_dX=0.0;
modelStruct.modelVar_CSRHSTI_i=mod.CSRHSTI_i;
modelStruct.d_modelVar_CSRHSTI_i_dX=0.0;
modelStruct.modelVar_CSRHGAT_i=mod.CSRHGAT_i;
modelStruct.d_modelVar_CSRHGAT_i_dX=0.0;
modelStruct.modelVar_CTATBOT_i=mod.CTATBOT_i;
modelStruct.d_modelVar_CTATBOT_i_dX=0.0;
modelStruct.modelVar_CTATSTI_i=mod.CTATSTI_i;
modelStruct.d_modelVar_CTATSTI_i_dX=0.0;
modelStruct.modelVar_CTATGAT_i=mod.CTATGAT_i;
modelStruct.d_modelVar_CTATGAT_i_dX=0.0;
modelStruct.modelVar_CBBTBOT_i=mod.CBBTBOT_i;
modelStruct.d_modelVar_CBBTBOT_i_dX=0.0;
modelStruct.modelVar_CBBTSTI_i=mod.CBBTSTI_i;
modelStruct.d_modelVar_CBBTSTI_i_dX=0.0;
modelStruct.modelVar_CBBTGAT_i=mod.CBBTGAT_i;
modelStruct.d_modelVar_CBBTGAT_i_dX=0.0;
modelStruct.modelVar_VBRBOT_i=mod.VBRBOT_i;
modelStruct.d_modelVar_VBRBOT_i_dX=0.0;
modelStruct.modelVar_VBRSTI_i=mod.VBRSTI_i;
modelStruct.d_modelVar_VBRSTI_i_dX=0.0;
modelStruct.modelVar_VBRGAT_i=mod.VBRGAT_i;
modelStruct.d_modelVar_VBRGAT_i_dX=0.0;
modelStruct.modelVar_PBRBOT_i=mod.PBRBOT_i;
modelStruct.d_modelVar_PBRBOT_i_dX=0.0;
modelStruct.modelVar_PBRSTI_i=mod.PBRSTI_i;
modelStruct.d_modelVar_PBRSTI_i_dX=0.0;
modelStruct.modelVar_PBRGAT_i=mod.PBRGAT_i;
modelStruct.d_modelVar_PBRGAT_i_dX=0.0;
modelStruct.modelVar_SWJUNEXP_i=mod.SWJUNEXP_i;
modelStruct.modelVar_VJUNREF_i=mod.VJUNREF_i;
modelStruct.d_modelVar_VJUNREF_i_dX=0.0;
modelStruct.modelVar_FJUNQ_i=mod.FJUNQ_i;
modelStruct.d_modelVar_FJUNQ_i_dX=0.0;
modelStruct.modelVar_phitr=mod.phitr;
modelStruct.d_modelVar_phitr_dX=0.0;
modelStruct.modelVar_phitd=mod.phitd;
modelStruct.d_modelVar_phitd_dX=0.0;
modelStruct.modelVar_phitdinv=mod.phitdinv;
modelStruct.d_modelVar_phitdinv_dX=0.0;
modelStruct.modelVar_perfc=mod.perfc;
modelStruct.modelVar_berfc=mod.berfc;
modelStruct.modelVar_cerfc=mod.cerfc;
modelStruct.modelVar_ftdbot=mod.ftdbot;
modelStruct.d_modelVar_ftdbot_dX=0.0;
modelStruct.modelVar_ftdsti=mod.ftdsti;
modelStruct.d_modelVar_ftdsti_dX=0.0;
modelStruct.modelVar_ftdgat=mod.ftdgat;
modelStruct.d_modelVar_ftdgat_dX=0.0;
modelStruct.modelVar_idsatbot=mod.idsatbot;
modelStruct.d_modelVar_idsatbot_dX=0.0;
modelStruct.modelVar_idsatsti=mod.idsatsti;
modelStruct.d_modelVar_idsatsti_dX=0.0;
modelStruct.modelVar_idsatgat=mod.idsatgat;
modelStruct.d_modelVar_idsatgat_dX=0.0;
modelStruct.modelVar_vbibot=mod.vbibot;
modelStruct.d_modelVar_vbibot_dX=0.0;
modelStruct.modelVar_vbisti=mod.vbisti;
modelStruct.d_modelVar_vbisti_dX=0.0;
modelStruct.modelVar_vbigat=mod.vbigat;
modelStruct.d_modelVar_vbigat_dX=0.0;
modelStruct.modelVar_vbiinvbot=mod.vbiinvbot;
modelStruct.d_modelVar_vbiinvbot_dX=0.0;
modelStruct.modelVar_vbiinvsti=mod.vbiinvsti;
modelStruct.d_modelVar_vbiinvsti_dX=0.0;
modelStruct.modelVar_vbiinvgat=mod.vbiinvgat;
modelStruct.d_modelVar_vbiinvgat_dX=0.0;
modelStruct.modelVar_one_minus_PBOT=mod.one_minus_PBOT;
modelStruct.d_modelVar_one_minus_PBOT_dX=0.0;
modelStruct.modelVar_one_minus_PSTI=mod.one_minus_PSTI;
modelStruct.d_modelVar_one_minus_PSTI_dX=0.0;
modelStruct.modelVar_one_minus_PGAT=mod.one_minus_PGAT;
modelStruct.d_modelVar_one_minus_PGAT_dX=0.0;
modelStruct.modelVar_one_over_one_minus_PBOT=mod.one_over_one_minus_PBOT;
modelStruct.d_modelVar_one_over_one_minus_PBOT_dX=0.0;
modelStruct.modelVar_one_over_one_minus_PSTI=mod.one_over_one_minus_PSTI;
modelStruct.d_modelVar_one_over_one_minus_PSTI_dX=0.0;
modelStruct.modelVar_one_over_one_minus_PGAT=mod.one_over_one_minus_PGAT;
modelStruct.d_modelVar_one_over_one_minus_PGAT_dX=0.0;
modelStruct.modelVar_cjobot=mod.cjobot;
modelStruct.d_modelVar_cjobot_dX=0.0;
modelStruct.modelVar_cjosti=mod.cjosti;
modelStruct.d_modelVar_cjosti_dX=0.0;
modelStruct.modelVar_cjogat=mod.cjogat;
modelStruct.d_modelVar_cjogat_dX=0.0;
modelStruct.modelVar_qprefbot=mod.qprefbot;
modelStruct.d_modelVar_qprefbot_dX=0.0;
modelStruct.modelVar_qprefsti=mod.qprefsti;
modelStruct.d_modelVar_qprefsti_dX=0.0;
modelStruct.modelVar_qprefgat=mod.qprefgat;
modelStruct.d_modelVar_qprefgat_dX=0.0;
modelStruct.modelVar_qpref2bot=mod.qpref2bot;
modelStruct.d_modelVar_qpref2bot_dX=0.0;
modelStruct.modelVar_qpref2sti=mod.qpref2sti;
modelStruct.d_modelVar_qpref2sti_dX=0.0;
modelStruct.modelVar_qpref2gat=mod.qpref2gat;
modelStruct.d_modelVar_qpref2gat_dX=0.0;
modelStruct.modelVar_wdepnulrbot=mod.wdepnulrbot;
modelStruct.d_modelVar_wdepnulrbot_dX=0.0;
modelStruct.modelVar_wdepnulrsti=mod.wdepnulrsti;
modelStruct.d_modelVar_wdepnulrsti_dX=0.0;
modelStruct.modelVar_wdepnulrgat=mod.wdepnulrgat;
modelStruct.d_modelVar_wdepnulrgat_dX=0.0;
modelStruct.modelVar_wdepnulrinvbot=mod.wdepnulrinvbot;
modelStruct.d_modelVar_wdepnulrinvbot_dX=0.0;
modelStruct.modelVar_wdepnulrinvsti=mod.wdepnulrinvsti;
modelStruct.d_modelVar_wdepnulrinvsti_dX=0.0;
modelStruct.modelVar_wdepnulrinvgat=mod.wdepnulrinvgat;
modelStruct.d_modelVar_wdepnulrinvgat_dX=0.0;
modelStruct.modelVar_VBIRBOTinv=mod.VBIRBOTinv;
modelStruct.d_modelVar_VBIRBOTinv_dX=0.0;
modelStruct.modelVar_VBIRSTIinv=mod.VBIRSTIinv;
modelStruct.d_modelVar_VBIRSTIinv_dX=0.0;
modelStruct.modelVar_VBIRGATinv=mod.VBIRGATinv;
modelStruct.d_modelVar_VBIRGATinv_dX=0.0;
modelStruct.modelVar_atatbot=mod.atatbot;
modelStruct.d_modelVar_atatbot_dX=0.0;
modelStruct.modelVar_atatsti=mod.atatsti;
modelStruct.d_modelVar_atatsti_dX=0.0;
modelStruct.modelVar_atatgat=mod.atatgat;
modelStruct.d_modelVar_atatgat_dX=0.0;
modelStruct.modelVar_btatpartbot=mod.btatpartbot;
modelStruct.d_modelVar_btatpartbot_dX=0.0;
modelStruct.modelVar_btatpartsti=mod.btatpartsti;
modelStruct.d_modelVar_btatpartsti_dX=0.0;
modelStruct.modelVar_btatpartgat=mod.btatpartgat;
modelStruct.d_modelVar_btatpartgat_dX=0.0;
modelStruct.modelVar_fbbtbot=mod.fbbtbot;
modelStruct.d_modelVar_fbbtbot_dX=0.0;
modelStruct.modelVar_fbbtsti=mod.fbbtsti;
modelStruct.d_modelVar_fbbtsti_dX=0.0;
modelStruct.modelVar_fbbtgat=mod.fbbtgat;
modelStruct.d_modelVar_fbbtgat_dX=0.0;
modelStruct.modelVar_alphaav=mod.alphaav;
modelStruct.d_modelVar_alphaav_dX=0.0;
modelStruct.modelVar_fstopbot=mod.fstopbot;
modelStruct.d_modelVar_fstopbot_dX=0.0;
modelStruct.modelVar_fstopsti=mod.fstopsti;
modelStruct.d_modelVar_fstopsti_dX=0.0;
modelStruct.modelVar_fstopgat=mod.fstopgat;
modelStruct.d_modelVar_fstopgat_dX=0.0;
modelStruct.modelVar_VBRinvbot=mod.VBRinvbot;
modelStruct.d_modelVar_VBRinvbot_dX=0.0;
modelStruct.modelVar_VBRinvsti=mod.VBRinvsti;
modelStruct.d_modelVar_VBRinvsti_dX=0.0;
modelStruct.modelVar_VBRinvgat=mod.VBRinvgat;
modelStruct.d_modelVar_VBRinvgat_dX=0.0;
modelStruct.modelVar_slopebot=mod.slopebot;
modelStruct.d_modelVar_slopebot_dX=0.0;
modelStruct.modelVar_slopesti=mod.slopesti;
modelStruct.d_modelVar_slopesti_dX=0.0;
modelStruct.modelVar_slopegat=mod.slopegat;
modelStruct.d_modelVar_slopegat_dX=0.0;


// non-reals



Linear::Vector * solVectorPtr = in.extData.nextSolVectorPtr;

// extract solution variables
probeVars[in.admsProbeID_V_A_GND] = (*solVectorPtr)[in.li_A];
probeVars[in.admsProbeID_V_A_K] = (*solVectorPtr)[in.li_A]- (*solVectorPtr)[in.li_K];



  // Need to use processParams-like function to process the
  // initial_model and initial_instance blocks with the LOCAL copies of
  // instance and model vars, and local copies of instance and model
  // params.
evaluateInitialModel(
modelStruct,
 mod.admsModTemp,in.getDeviceOptions().gmin,in);
evaluateInitialInstance(
instanceStruct,
modelStruct,
in.admsTemperature,in.adms_vt_nom,in.getDeviceOptions().gmin,in);


// Now call  the function that does the heavy lifting.
evaluateModelEquations(
probeVars,
// probe constants
in.admsProbeID_V_A_GND,
in.admsProbeID_V_A_K,

// node constants
in.admsNodeID_A,
in.admsNodeID_K,
instanceStruct,
modelStruct,
 in.admsTemperature,
 in.adms_vt_nom,
 in.getDeviceOptions().gmin,
 d_staticContributions_dX,
 d_dynamicContributions_dX,
 in);


// We now have the F and Q vector stuff, populate the dependencies:

    dfdp[in.admsNodeID_A] += d_staticContributions_dX[in.admsNodeID_A];
    dqdp[in.admsNodeID_A] += d_dynamicContributions_dX[in.admsNodeID_A];
    Findices[in.admsNodeID_A] = in.li_A;
    Qindices[in.admsNodeID_A] = in.li_A;
    dfdp[in.admsNodeID_K] += d_staticContributions_dX[in.admsNodeID_K];
    dqdp[in.admsNodeID_K] += d_dynamicContributions_dX[in.admsNodeID_K];
    Findices[in.admsNodeID_K] = in.li_K;
    Qindices[in.admsNodeID_K] = in.li_K;


}

//-----------------------------------------------------------------------------
// Function      : ModelSensitivity::operator()
// Purpose       : return sensitivity for a single model parameter
// Special Notes :
// Scope         : public
// Creator       : admsXml
// Creation Date :
//-----------------------------------------------------------------------------
/// Compute sensitivity to a specified model
/// parameter of all device instances of that model's outputs
///
///
/// @param[in] entity  The device entity that owns the parameter
/// @param[in] name    The unadorned parameter name specific to the entity
/// @param[out] dfdp   The derivative of the F vector with respect to the parameter
/// @param[out] dqdp   The derivative of the Q vector with respect to the parameter
/// @param[out] dbdp   The derivative of the B vector with respect to the parameter
/// @param[out] Findices   The indices into the F vector corresponding to the elements of dfdp
/// @param[out] Qindices   The indices into the Q vector corresponding to the elements of dfdp
/// @param[out] Bindices   The indices into the B vector corresponding to the elements of dfdp
///
///
void ModelSensitivity::operator()
(
const ParameterBase &entity,
const std::string &name,
std::vector<double> & dfdp,
std::vector<double> & dqdp,
std::vector<double> & dbdp,
std::vector<int> & Findices,
std::vector<int> & Qindices,
std::vector<int> & Bindices
) const
{
const ParameterBase * e1 = &entity;
const Model & mod = *(dynamic_cast<const Model *> (e1));
int sizeInstance = mod.instanceContainer.size();

dfdp.resize((2+0)*sizeInstance);
dqdp.resize((2+0)*sizeInstance);
Findices.resize((2+0)*sizeInstance);
Qindices.resize((2+0)*sizeInstance);

std::vector <double> probeVars(2);
std::vector <double> d_staticContributions_dX(2+0);
std::vector <double> d_dynamicContributions_dX(2+0);


// Copy out all the model parameters (doubles) into local structure
modelSensStruct modelStruct;

// Keep a map so we can set the right one to the independent variable
// We do this solely to avoid a big ugly "if/else" block just to find the
// one parameter we're doing sensitivities on.
unordered_map <std::string,double*,HashNoCase,EqualNoCase> modParamMap;

// reals
modelStruct.modelPar_DTA=mod.DTA;
modelStruct.d_modelPar_DTA_dX=0.0;
modelStruct.modelPar_given_DTA=mod.given("DTA");
modParamMap["DTA"] = &(modelStruct.d_modelPar_DTA_dX);
modelStruct.modelPar_IMAX=mod.IMAX;
modelStruct.d_modelPar_IMAX_dX=0.0;
modelStruct.modelPar_given_IMAX=mod.given("IMAX");
modParamMap["IMAX"] = &(modelStruct.d_modelPar_IMAX_dX);
modelStruct.modelPar_TRJ=mod.TRJ;
modelStruct.d_modelPar_TRJ_dX=0.0;
modelStruct.modelPar_given_TRJ=mod.given("TRJ");
modParamMap["TRJ"] = &(modelStruct.d_modelPar_TRJ_dX);
modelStruct.modelPar_FREV=mod.FREV;
modelStruct.d_modelPar_FREV_dX=0.0;
modelStruct.modelPar_given_FREV=mod.given("FREV");
modParamMap["FREV"] = &(modelStruct.d_modelPar_FREV_dX);
modelStruct.modelPar_CJORBOT=mod.CJORBOT;
modelStruct.d_modelPar_CJORBOT_dX=0.0;
modelStruct.modelPar_given_CJORBOT=mod.given("CJORBOT");
modParamMap["CJORBOT"] = &(modelStruct.d_modelPar_CJORBOT_dX);
modelStruct.modelPar_CJORSTI=mod.CJORSTI;
modelStruct.d_modelPar_CJORSTI_dX=0.0;
modelStruct.modelPar_given_CJORSTI=mod.given("CJORSTI");
modParamMap["CJORSTI"] = &(modelStruct.d_modelPar_CJORSTI_dX);
modelStruct.modelPar_CJORGAT=mod.CJORGAT;
modelStruct.d_modelPar_CJORGAT_dX=0.0;
modelStruct.modelPar_given_CJORGAT=mod.given("CJORGAT");
modParamMap["CJORGAT"] = &(modelStruct.d_modelPar_CJORGAT_dX);
modelStruct.modelPar_VBIRBOT=mod.VBIRBOT;
modelStruct.d_modelPar_VBIRBOT_dX=0.0;
modelStruct.modelPar_given_VBIRBOT=mod.given("VBIRBOT");
modParamMap["VBIRBOT"] = &(modelStruct.d_modelPar_VBIRBOT_dX);
modelStruct.modelPar_VBIRSTI=mod.VBIRSTI;
modelStruct.d_modelPar_VBIRSTI_dX=0.0;
modelStruct.modelPar_given_VBIRSTI=mod.given("VBIRSTI");
modParamMap["VBIRSTI"] = &(modelStruct.d_modelPar_VBIRSTI_dX);
modelStruct.modelPar_VBIRGAT=mod.VBIRGAT;
modelStruct.d_modelPar_VBIRGAT_dX=0.0;
modelStruct.modelPar_given_VBIRGAT=mod.given("VBIRGAT");
modParamMap["VBIRGAT"] = &(modelStruct.d_modelPar_VBIRGAT_dX);
modelStruct.modelPar_PBOT=mod.PBOT;
modelStruct.d_modelPar_PBOT_dX=0.0;
modelStruct.modelPar_given_PBOT=mod.given("PBOT");
modParamMap["PBOT"] = &(modelStruct.d_modelPar_PBOT_dX);
modelStruct.modelPar_PSTI=mod.PSTI;
modelStruct.d_modelPar_PSTI_dX=0.0;
modelStruct.modelPar_given_PSTI=mod.given("PSTI");
modParamMap["PSTI"] = &(modelStruct.d_modelPar_PSTI_dX);
modelStruct.modelPar_PGAT=mod.PGAT;
modelStruct.d_modelPar_PGAT_dX=0.0;
modelStruct.modelPar_given_PGAT=mod.given("PGAT");
modParamMap["PGAT"] = &(modelStruct.d_modelPar_PGAT_dX);
modelStruct.modelPar_PHIGBOT=mod.PHIGBOT;
modelStruct.d_modelPar_PHIGBOT_dX=0.0;
modelStruct.modelPar_given_PHIGBOT=mod.given("PHIGBOT");
modParamMap["PHIGBOT"] = &(modelStruct.d_modelPar_PHIGBOT_dX);
modelStruct.modelPar_PHIGSTI=mod.PHIGSTI;
modelStruct.d_modelPar_PHIGSTI_dX=0.0;
modelStruct.modelPar_given_PHIGSTI=mod.given("PHIGSTI");
modParamMap["PHIGSTI"] = &(modelStruct.d_modelPar_PHIGSTI_dX);
modelStruct.modelPar_PHIGGAT=mod.PHIGGAT;
modelStruct.d_modelPar_PHIGGAT_dX=0.0;
modelStruct.modelPar_given_PHIGGAT=mod.given("PHIGGAT");
modParamMap["PHIGGAT"] = &(modelStruct.d_modelPar_PHIGGAT_dX);
modelStruct.modelPar_IDSATRBOT=mod.IDSATRBOT;
modelStruct.d_modelPar_IDSATRBOT_dX=0.0;
modelStruct.modelPar_given_IDSATRBOT=mod.given("IDSATRBOT");
modParamMap["IDSATRBOT"] = &(modelStruct.d_modelPar_IDSATRBOT_dX);
modelStruct.modelPar_IDSATRSTI=mod.IDSATRSTI;
modelStruct.d_modelPar_IDSATRSTI_dX=0.0;
modelStruct.modelPar_given_IDSATRSTI=mod.given("IDSATRSTI");
modParamMap["IDSATRSTI"] = &(modelStruct.d_modelPar_IDSATRSTI_dX);
modelStruct.modelPar_IDSATRGAT=mod.IDSATRGAT;
modelStruct.d_modelPar_IDSATRGAT_dX=0.0;
modelStruct.modelPar_given_IDSATRGAT=mod.given("IDSATRGAT");
modParamMap["IDSATRGAT"] = &(modelStruct.d_modelPar_IDSATRGAT_dX);
modelStruct.modelPar_CSRHBOT=mod.CSRHBOT;
modelStruct.d_modelPar_CSRHBOT_dX=0.0;
modelStruct.modelPar_given_CSRHBOT=mod.given("CSRHBOT");
modParamMap["CSRHBOT"] = &(modelStruct.d_modelPar_CSRHBOT_dX);
modelStruct.modelPar_CSRHSTI=mod.CSRHSTI;
modelStruct.d_modelPar_CSRHSTI_dX=0.0;
modelStruct.modelPar_given_CSRHSTI=mod.given("CSRHSTI");
modParamMap["CSRHSTI"] = &(modelStruct.d_modelPar_CSRHSTI_dX);
modelStruct.modelPar_CSRHGAT=mod.CSRHGAT;
modelStruct.d_modelPar_CSRHGAT_dX=0.0;
modelStruct.modelPar_given_CSRHGAT=mod.given("CSRHGAT");
modParamMap["CSRHGAT"] = &(modelStruct.d_modelPar_CSRHGAT_dX);
modelStruct.modelPar_XJUNSTI=mod.XJUNSTI;
modelStruct.d_modelPar_XJUNSTI_dX=0.0;
modelStruct.modelPar_given_XJUNSTI=mod.given("XJUNSTI");
modParamMap["XJUNSTI"] = &(modelStruct.d_modelPar_XJUNSTI_dX);
modelStruct.modelPar_XJUNGAT=mod.XJUNGAT;
modelStruct.d_modelPar_XJUNGAT_dX=0.0;
modelStruct.modelPar_given_XJUNGAT=mod.given("XJUNGAT");
modParamMap["XJUNGAT"] = &(modelStruct.d_modelPar_XJUNGAT_dX);
modelStruct.modelPar_CTATBOT=mod.CTATBOT;
modelStruct.d_modelPar_CTATBOT_dX=0.0;
modelStruct.modelPar_given_CTATBOT=mod.given("CTATBOT");
modParamMap["CTATBOT"] = &(modelStruct.d_modelPar_CTATBOT_dX);
modelStruct.modelPar_CTATSTI=mod.CTATSTI;
modelStruct.d_modelPar_CTATSTI_dX=0.0;
modelStruct.modelPar_given_CTATSTI=mod.given("CTATSTI");
modParamMap["CTATSTI"] = &(modelStruct.d_modelPar_CTATSTI_dX);
modelStruct.modelPar_CTATGAT=mod.CTATGAT;
modelStruct.d_modelPar_CTATGAT_dX=0.0;
modelStruct.modelPar_given_CTATGAT=mod.given("CTATGAT");
modParamMap["CTATGAT"] = &(modelStruct.d_modelPar_CTATGAT_dX);
modelStruct.modelPar_MEFFTATBOT=mod.MEFFTATBOT;
modelStruct.d_modelPar_MEFFTATBOT_dX=0.0;
modelStruct.modelPar_given_MEFFTATBOT=mod.given("MEFFTATBOT");
modParamMap["MEFFTATBOT"] = &(modelStruct.d_modelPar_MEFFTATBOT_dX);
modelStruct.modelPar_MEFFTATSTI=mod.MEFFTATSTI;
modelStruct.d_modelPar_MEFFTATSTI_dX=0.0;
modelStruct.modelPar_given_MEFFTATSTI=mod.given("MEFFTATSTI");
modParamMap["MEFFTATSTI"] = &(modelStruct.d_modelPar_MEFFTATSTI_dX);
modelStruct.modelPar_MEFFTATGAT=mod.MEFFTATGAT;
modelStruct.d_modelPar_MEFFTATGAT_dX=0.0;
modelStruct.modelPar_given_MEFFTATGAT=mod.given("MEFFTATGAT");
modParamMap["MEFFTATGAT"] = &(modelStruct.d_modelPar_MEFFTATGAT_dX);
modelStruct.modelPar_CBBTBOT=mod.CBBTBOT;
modelStruct.d_modelPar_CBBTBOT_dX=0.0;
modelStruct.modelPar_given_CBBTBOT=mod.given("CBBTBOT");
modParamMap["CBBTBOT"] = &(modelStruct.d_modelPar_CBBTBOT_dX);
modelStruct.modelPar_CBBTSTI=mod.CBBTSTI;
modelStruct.d_modelPar_CBBTSTI_dX=0.0;
modelStruct.modelPar_given_CBBTSTI=mod.given("CBBTSTI");
modParamMap["CBBTSTI"] = &(modelStruct.d_modelPar_CBBTSTI_dX);
modelStruct.modelPar_CBBTGAT=mod.CBBTGAT;
modelStruct.d_modelPar_CBBTGAT_dX=0.0;
modelStruct.modelPar_given_CBBTGAT=mod.given("CBBTGAT");
modParamMap["CBBTGAT"] = &(modelStruct.d_modelPar_CBBTGAT_dX);
modelStruct.modelPar_FBBTRBOT=mod.FBBTRBOT;
modelStruct.d_modelPar_FBBTRBOT_dX=0.0;
modelStruct.modelPar_given_FBBTRBOT=mod.given("FBBTRBOT");
modParamMap["FBBTRBOT"] = &(modelStruct.d_modelPar_FBBTRBOT_dX);
modelStruct.modelPar_FBBTRSTI=mod.FBBTRSTI;
modelStruct.d_modelPar_FBBTRSTI_dX=0.0;
modelStruct.modelPar_given_FBBTRSTI=mod.given("FBBTRSTI");
modParamMap["FBBTRSTI"] = &(modelStruct.d_modelPar_FBBTRSTI_dX);
modelStruct.modelPar_FBBTRGAT=mod.FBBTRGAT;
modelStruct.d_modelPar_FBBTRGAT_dX=0.0;
modelStruct.modelPar_given_FBBTRGAT=mod.given("FBBTRGAT");
modParamMap["FBBTRGAT"] = &(modelStruct.d_modelPar_FBBTRGAT_dX);
modelStruct.modelPar_STFBBTBOT=mod.STFBBTBOT;
modelStruct.d_modelPar_STFBBTBOT_dX=0.0;
modelStruct.modelPar_given_STFBBTBOT=mod.given("STFBBTBOT");
modParamMap["STFBBTBOT"] = &(modelStruct.d_modelPar_STFBBTBOT_dX);
modelStruct.modelPar_STFBBTSTI=mod.STFBBTSTI;
modelStruct.d_modelPar_STFBBTSTI_dX=0.0;
modelStruct.modelPar_given_STFBBTSTI=mod.given("STFBBTSTI");
modParamMap["STFBBTSTI"] = &(modelStruct.d_modelPar_STFBBTSTI_dX);
modelStruct.modelPar_STFBBTGAT=mod.STFBBTGAT;
modelStruct.d_modelPar_STFBBTGAT_dX=0.0;
modelStruct.modelPar_given_STFBBTGAT=mod.given("STFBBTGAT");
modParamMap["STFBBTGAT"] = &(modelStruct.d_modelPar_STFBBTGAT_dX);
modelStruct.modelPar_VBRBOT=mod.VBRBOT;
modelStruct.d_modelPar_VBRBOT_dX=0.0;
modelStruct.modelPar_given_VBRBOT=mod.given("VBRBOT");
modParamMap["VBRBOT"] = &(modelStruct.d_modelPar_VBRBOT_dX);
modelStruct.modelPar_VBRSTI=mod.VBRSTI;
modelStruct.d_modelPar_VBRSTI_dX=0.0;
modelStruct.modelPar_given_VBRSTI=mod.given("VBRSTI");
modParamMap["VBRSTI"] = &(modelStruct.d_modelPar_VBRSTI_dX);
modelStruct.modelPar_VBRGAT=mod.VBRGAT;
modelStruct.d_modelPar_VBRGAT_dX=0.0;
modelStruct.modelPar_given_VBRGAT=mod.given("VBRGAT");
modParamMap["VBRGAT"] = &(modelStruct.d_modelPar_VBRGAT_dX);
modelStruct.modelPar_PBRBOT=mod.PBRBOT;
modelStruct.d_modelPar_PBRBOT_dX=0.0;
modelStruct.modelPar_given_PBRBOT=mod.given("PBRBOT");
modParamMap["PBRBOT"] = &(modelStruct.d_modelPar_PBRBOT_dX);
modelStruct.modelPar_PBRSTI=mod.PBRSTI;
modelStruct.d_modelPar_PBRSTI_dX=0.0;
modelStruct.modelPar_given_PBRSTI=mod.given("PBRSTI");
modParamMap["PBRSTI"] = &(modelStruct.d_modelPar_PBRSTI_dX);
modelStruct.modelPar_PBRGAT=mod.PBRGAT;
modelStruct.d_modelPar_PBRGAT_dX=0.0;
modelStruct.modelPar_given_PBRGAT=mod.given("PBRGAT");
modParamMap["PBRGAT"] = &(modelStruct.d_modelPar_PBRGAT_dX);
modelStruct.modelPar_SWJUNEXP=mod.SWJUNEXP;
modelStruct.d_modelPar_SWJUNEXP_dX=0.0;
modelStruct.modelPar_given_SWJUNEXP=mod.given("SWJUNEXP");
modParamMap["SWJUNEXP"] = &(modelStruct.d_modelPar_SWJUNEXP_dX);
modelStruct.modelPar_VJUNREF=mod.VJUNREF;
modelStruct.d_modelPar_VJUNREF_dX=0.0;
modelStruct.modelPar_given_VJUNREF=mod.given("VJUNREF");
modParamMap["VJUNREF"] = &(modelStruct.d_modelPar_VJUNREF_dX);
modelStruct.modelPar_FJUNQ=mod.FJUNQ;
modelStruct.d_modelPar_FJUNQ_dX=0.0;
modelStruct.modelPar_given_FJUNQ=mod.given("FJUNQ");
modParamMap["FJUNQ"] = &(modelStruct.d_modelPar_FJUNQ_dX);


// hidden reals


// non-reals (including hiddens)
modelStruct.modelPar_LEVEL=mod.LEVEL;
modelStruct.modelPar_given_LEVEL=mod.given("LEVEL");
modelStruct.modelPar_TYPE=mod.TYPE;
modelStruct.modelPar_given_TYPE=mod.given("TYPE");


// Set the one parameter whose name was passed in to be the independent
// variable for differentiation purposes.  Since we stored variable pointers, this
// makes sure that that ONE variable gets set right.
// FIXME: make this check name for presence first!  Segfault on invalid.
*(modParamMap[name])=1.0;

//make local copies of all model vars
//reals
modelStruct.modelVar_IMAX_i=mod.IMAX_i;
modelStruct.d_modelVar_IMAX_i_dX=0.0;
modelStruct.modelVar_VBIRBOT_i=mod.VBIRBOT_i;
modelStruct.d_modelVar_VBIRBOT_i_dX=0.0;
modelStruct.modelVar_VBIRSTI_i=mod.VBIRSTI_i;
modelStruct.d_modelVar_VBIRSTI_i_dX=0.0;
modelStruct.modelVar_VBIRGAT_i=mod.VBIRGAT_i;
modelStruct.d_modelVar_VBIRGAT_i_dX=0.0;
modelStruct.modelVar_PBOT_i=mod.PBOT_i;
modelStruct.d_modelVar_PBOT_i_dX=0.0;
modelStruct.modelVar_PSTI_i=mod.PSTI_i;
modelStruct.d_modelVar_PSTI_i_dX=0.0;
modelStruct.modelVar_PGAT_i=mod.PGAT_i;
modelStruct.d_modelVar_PGAT_i_dX=0.0;
modelStruct.modelVar_CSRHBOT_i=mod.CSRHBOT_i;
modelStruct.d_modelVar_CSRHBOT_i_dX=0.0;
modelStruct.modelVar_CSRHSTI_i=mod.CSRHSTI_i;
modelStruct.d_modelVar_CSRHSTI_i_dX=0.0;
modelStruct.modelVar_CSRHGAT_i=mod.CSRHGAT_i;
modelStruct.d_modelVar_CSRHGAT_i_dX=0.0;
modelStruct.modelVar_CTATBOT_i=mod.CTATBOT_i;
modelStruct.d_modelVar_CTATBOT_i_dX=0.0;
modelStruct.modelVar_CTATSTI_i=mod.CTATSTI_i;
modelStruct.d_modelVar_CTATSTI_i_dX=0.0;
modelStruct.modelVar_CTATGAT_i=mod.CTATGAT_i;
modelStruct.d_modelVar_CTATGAT_i_dX=0.0;
modelStruct.modelVar_CBBTBOT_i=mod.CBBTBOT_i;
modelStruct.d_modelVar_CBBTBOT_i_dX=0.0;
modelStruct.modelVar_CBBTSTI_i=mod.CBBTSTI_i;
modelStruct.d_modelVar_CBBTSTI_i_dX=0.0;
modelStruct.modelVar_CBBTGAT_i=mod.CBBTGAT_i;
modelStruct.d_modelVar_CBBTGAT_i_dX=0.0;
modelStruct.modelVar_VBRBOT_i=mod.VBRBOT_i;
modelStruct.d_modelVar_VBRBOT_i_dX=0.0;
modelStruct.modelVar_VBRSTI_i=mod.VBRSTI_i;
modelStruct.d_modelVar_VBRSTI_i_dX=0.0;
modelStruct.modelVar_VBRGAT_i=mod.VBRGAT_i;
modelStruct.d_modelVar_VBRGAT_i_dX=0.0;
modelStruct.modelVar_PBRBOT_i=mod.PBRBOT_i;
modelStruct.d_modelVar_PBRBOT_i_dX=0.0;
modelStruct.modelVar_PBRSTI_i=mod.PBRSTI_i;
modelStruct.d_modelVar_PBRSTI_i_dX=0.0;
modelStruct.modelVar_PBRGAT_i=mod.PBRGAT_i;
modelStruct.d_modelVar_PBRGAT_i_dX=0.0;
modelStruct.modelVar_SWJUNEXP_i=mod.SWJUNEXP_i;
modelStruct.modelVar_VJUNREF_i=mod.VJUNREF_i;
modelStruct.d_modelVar_VJUNREF_i_dX=0.0;
modelStruct.modelVar_FJUNQ_i=mod.FJUNQ_i;
modelStruct.d_modelVar_FJUNQ_i_dX=0.0;
modelStruct.modelVar_phitr=mod.phitr;
modelStruct.d_modelVar_phitr_dX=0.0;
modelStruct.modelVar_phitd=mod.phitd;
modelStruct.d_modelVar_phitd_dX=0.0;
modelStruct.modelVar_phitdinv=mod.phitdinv;
modelStruct.d_modelVar_phitdinv_dX=0.0;
modelStruct.modelVar_perfc=mod.perfc;
modelStruct.modelVar_berfc=mod.berfc;
modelStruct.modelVar_cerfc=mod.cerfc;
modelStruct.modelVar_ftdbot=mod.ftdbot;
modelStruct.d_modelVar_ftdbot_dX=0.0;
modelStruct.modelVar_ftdsti=mod.ftdsti;
modelStruct.d_modelVar_ftdsti_dX=0.0;
modelStruct.modelVar_ftdgat=mod.ftdgat;
modelStruct.d_modelVar_ftdgat_dX=0.0;
modelStruct.modelVar_idsatbot=mod.idsatbot;
modelStruct.d_modelVar_idsatbot_dX=0.0;
modelStruct.modelVar_idsatsti=mod.idsatsti;
modelStruct.d_modelVar_idsatsti_dX=0.0;
modelStruct.modelVar_idsatgat=mod.idsatgat;
modelStruct.d_modelVar_idsatgat_dX=0.0;
modelStruct.modelVar_vbibot=mod.vbibot;
modelStruct.d_modelVar_vbibot_dX=0.0;
modelStruct.modelVar_vbisti=mod.vbisti;
modelStruct.d_modelVar_vbisti_dX=0.0;
modelStruct.modelVar_vbigat=mod.vbigat;
modelStruct.d_modelVar_vbigat_dX=0.0;
modelStruct.modelVar_vbiinvbot=mod.vbiinvbot;
modelStruct.d_modelVar_vbiinvbot_dX=0.0;
modelStruct.modelVar_vbiinvsti=mod.vbiinvsti;
modelStruct.d_modelVar_vbiinvsti_dX=0.0;
modelStruct.modelVar_vbiinvgat=mod.vbiinvgat;
modelStruct.d_modelVar_vbiinvgat_dX=0.0;
modelStruct.modelVar_one_minus_PBOT=mod.one_minus_PBOT;
modelStruct.d_modelVar_one_minus_PBOT_dX=0.0;
modelStruct.modelVar_one_minus_PSTI=mod.one_minus_PSTI;
modelStruct.d_modelVar_one_minus_PSTI_dX=0.0;
modelStruct.modelVar_one_minus_PGAT=mod.one_minus_PGAT;
modelStruct.d_modelVar_one_minus_PGAT_dX=0.0;
modelStruct.modelVar_one_over_one_minus_PBOT=mod.one_over_one_minus_PBOT;
modelStruct.d_modelVar_one_over_one_minus_PBOT_dX=0.0;
modelStruct.modelVar_one_over_one_minus_PSTI=mod.one_over_one_minus_PSTI;
modelStruct.d_modelVar_one_over_one_minus_PSTI_dX=0.0;
modelStruct.modelVar_one_over_one_minus_PGAT=mod.one_over_one_minus_PGAT;
modelStruct.d_modelVar_one_over_one_minus_PGAT_dX=0.0;
modelStruct.modelVar_cjobot=mod.cjobot;
modelStruct.d_modelVar_cjobot_dX=0.0;
modelStruct.modelVar_cjosti=mod.cjosti;
modelStruct.d_modelVar_cjosti_dX=0.0;
modelStruct.modelVar_cjogat=mod.cjogat;
modelStruct.d_modelVar_cjogat_dX=0.0;
modelStruct.modelVar_qprefbot=mod.qprefbot;
modelStruct.d_modelVar_qprefbot_dX=0.0;
modelStruct.modelVar_qprefsti=mod.qprefsti;
modelStruct.d_modelVar_qprefsti_dX=0.0;
modelStruct.modelVar_qprefgat=mod.qprefgat;
modelStruct.d_modelVar_qprefgat_dX=0.0;
modelStruct.modelVar_qpref2bot=mod.qpref2bot;
modelStruct.d_modelVar_qpref2bot_dX=0.0;
modelStruct.modelVar_qpref2sti=mod.qpref2sti;
modelStruct.d_modelVar_qpref2sti_dX=0.0;
modelStruct.modelVar_qpref2gat=mod.qpref2gat;
modelStruct.d_modelVar_qpref2gat_dX=0.0;
modelStruct.modelVar_wdepnulrbot=mod.wdepnulrbot;
modelStruct.d_modelVar_wdepnulrbot_dX=0.0;
modelStruct.modelVar_wdepnulrsti=mod.wdepnulrsti;
modelStruct.d_modelVar_wdepnulrsti_dX=0.0;
modelStruct.modelVar_wdepnulrgat=mod.wdepnulrgat;
modelStruct.d_modelVar_wdepnulrgat_dX=0.0;
modelStruct.modelVar_wdepnulrinvbot=mod.wdepnulrinvbot;
modelStruct.d_modelVar_wdepnulrinvbot_dX=0.0;
modelStruct.modelVar_wdepnulrinvsti=mod.wdepnulrinvsti;
modelStruct.d_modelVar_wdepnulrinvsti_dX=0.0;
modelStruct.modelVar_wdepnulrinvgat=mod.wdepnulrinvgat;
modelStruct.d_modelVar_wdepnulrinvgat_dX=0.0;
modelStruct.modelVar_VBIRBOTinv=mod.VBIRBOTinv;
modelStruct.d_modelVar_VBIRBOTinv_dX=0.0;
modelStruct.modelVar_VBIRSTIinv=mod.VBIRSTIinv;
modelStruct.d_modelVar_VBIRSTIinv_dX=0.0;
modelStruct.modelVar_VBIRGATinv=mod.VBIRGATinv;
modelStruct.d_modelVar_VBIRGATinv_dX=0.0;
modelStruct.modelVar_atatbot=mod.atatbot;
modelStruct.d_modelVar_atatbot_dX=0.0;
modelStruct.modelVar_atatsti=mod.atatsti;
modelStruct.d_modelVar_atatsti_dX=0.0;
modelStruct.modelVar_atatgat=mod.atatgat;
modelStruct.d_modelVar_atatgat_dX=0.0;
modelStruct.modelVar_btatpartbot=mod.btatpartbot;
modelStruct.d_modelVar_btatpartbot_dX=0.0;
modelStruct.modelVar_btatpartsti=mod.btatpartsti;
modelStruct.d_modelVar_btatpartsti_dX=0.0;
modelStruct.modelVar_btatpartgat=mod.btatpartgat;
modelStruct.d_modelVar_btatpartgat_dX=0.0;
modelStruct.modelVar_fbbtbot=mod.fbbtbot;
modelStruct.d_modelVar_fbbtbot_dX=0.0;
modelStruct.modelVar_fbbtsti=mod.fbbtsti;
modelStruct.d_modelVar_fbbtsti_dX=0.0;
modelStruct.modelVar_fbbtgat=mod.fbbtgat;
modelStruct.d_modelVar_fbbtgat_dX=0.0;
modelStruct.modelVar_alphaav=mod.alphaav;
modelStruct.d_modelVar_alphaav_dX=0.0;
modelStruct.modelVar_fstopbot=mod.fstopbot;
modelStruct.d_modelVar_fstopbot_dX=0.0;
modelStruct.modelVar_fstopsti=mod.fstopsti;
modelStruct.d_modelVar_fstopsti_dX=0.0;
modelStruct.modelVar_fstopgat=mod.fstopgat;
modelStruct.d_modelVar_fstopgat_dX=0.0;
modelStruct.modelVar_VBRinvbot=mod.VBRinvbot;
modelStruct.d_modelVar_VBRinvbot_dX=0.0;
modelStruct.modelVar_VBRinvsti=mod.VBRinvsti;
modelStruct.d_modelVar_VBRinvsti_dX=0.0;
modelStruct.modelVar_VBRinvgat=mod.VBRinvgat;
modelStruct.d_modelVar_VBRinvgat_dX=0.0;
modelStruct.modelVar_slopebot=mod.slopebot;
modelStruct.d_modelVar_slopebot_dX=0.0;
modelStruct.modelVar_slopesti=mod.slopesti;
modelStruct.d_modelVar_slopesti_dX=0.0;
modelStruct.modelVar_slopegat=mod.slopegat;
modelStruct.d_modelVar_slopegat_dX=0.0;


// non-reals



// Now loop over all instances and do the deed
int inst=0;
for (std::vector<Instance*>::const_iterator in_it=mod.instanceContainer.begin(); in_it != mod.instanceContainer.end(); ++in_it,++inst)
{

  Instance & in=*(*in_it);
  // initialize contributions to zero (automatically sets derivatives to zero)
  for (int i=0; i < 2+0 ; ++i)
  {
  d_staticContributions_dX[i]=0;
  d_dynamicContributions_dX[i]=0;
  }



  // Copy out all the instance parameters (doubles) into local struct
 instanceSensStruct instanceStruct;

 // reals
instanceStruct.instancePar_AB=in.AB;
instanceStruct.d_instancePar_AB_dX=0.0;
instanceStruct.instancePar_given_AB=in.given("AB");
instanceStruct.instancePar_LS=in.LS;
instanceStruct.d_instancePar_LS_dX=0.0;
instanceStruct.instancePar_given_LS=in.given("LS");
instanceStruct.instancePar_LG=in.LG;
instanceStruct.d_instancePar_LG_dX=0.0;
instanceStruct.instancePar_given_LG=in.given("LG");
instanceStruct.instancePar_MULT=in.MULT;
instanceStruct.d_instancePar_MULT_dX=0.0;
instanceStruct.instancePar_given_MULT=in.given("MULT");


  // real hidden instance


  // Copy all the non-real instance params into vars of their appropriate type:




  // If there are any instance parameters that were not given, and have
  // corresponding model params, copy the model param into the instance.
  // This was already done by the instance constructor, but we do it again
  // because now we're propagating derivatives, and the user could be trying
  // to get sensitivity to the model parameter.


  //make local copies of all instance vars
  //reals
instanceStruct.instanceVar_MULT_i=in.MULT_i;
instanceStruct.d_instanceVar_MULT_i_dX=0.0;
instanceStruct.instanceVar_AB_i=in.AB_i;
instanceStruct.d_instanceVar_AB_i_dX=0.0;
instanceStruct.instanceVar_LS_i=in.LS_i;
instanceStruct.d_instanceVar_LS_i_dX=0.0;
instanceStruct.instanceVar_LG_i=in.LG_i;
instanceStruct.d_instanceVar_LG_i_dX=0.0;
instanceStruct.instanceVar_zflagbot=in.zflagbot;
instanceStruct.instanceVar_zflagsti=in.zflagsti;
instanceStruct.instanceVar_zflaggat=in.zflaggat;
instanceStruct.instanceVar_VMAX=in.VMAX;
instanceStruct.d_instanceVar_VMAX_dX=0.0;
instanceStruct.instanceVar_exp_VMAX_over_phitd=in.exp_VMAX_over_phitd;
instanceStruct.d_instanceVar_exp_VMAX_over_phitd_dX=0.0;
instanceStruct.instanceVar_vbimin=in.vbimin;
instanceStruct.d_instanceVar_vbimin_dX=0.0;
instanceStruct.instanceVar_vch=in.vch;
instanceStruct.d_instanceVar_vch_dX=0.0;
instanceStruct.instanceVar_vfmin=in.vfmin;
instanceStruct.d_instanceVar_vfmin_dX=0.0;
instanceStruct.instanceVar_vbbtlim=in.vbbtlim;
instanceStruct.d_instanceVar_vbbtlim_dX=0.0;
instanceStruct.instanceVar_xhighf1=in.xhighf1;
instanceStruct.d_instanceVar_xhighf1_dX=0.0;
instanceStruct.instanceVar_expxhf1=in.expxhf1;
instanceStruct.d_instanceVar_expxhf1_dX=0.0;
instanceStruct.instanceVar_xhighf2=in.xhighf2;
instanceStruct.d_instanceVar_xhighf2_dX=0.0;
instanceStruct.instanceVar_expxhf2=in.expxhf2;
instanceStruct.d_instanceVar_expxhf2_dX=0.0;
instanceStruct.instanceVar_xhighr=in.xhighr;
instanceStruct.d_instanceVar_xhighr_dX=0.0;
instanceStruct.instanceVar_expxhr=in.expxhr;
instanceStruct.d_instanceVar_expxhr_dX=0.0;
instanceStruct.instanceVar_ISATFOR1=in.ISATFOR1;
instanceStruct.d_instanceVar_ISATFOR1_dX=0.0;
instanceStruct.instanceVar_MFOR1=in.MFOR1;
instanceStruct.instanceVar_ISATFOR2=in.ISATFOR2;
instanceStruct.d_instanceVar_ISATFOR2_dX=0.0;
instanceStruct.instanceVar_MFOR2=in.MFOR2;
instanceStruct.d_instanceVar_MFOR2_dX=0.0;
instanceStruct.instanceVar_ISATREV=in.ISATREV;
instanceStruct.d_instanceVar_ISATREV_dX=0.0;
instanceStruct.instanceVar_MREV=in.MREV;
instanceStruct.d_instanceVar_MREV_dX=0.0;
instanceStruct.instanceVar_m0flag=in.m0flag;


  //non-reals



  Linear::Vector * solVectorPtr = in.extData.nextSolVectorPtr;

  // extract solution variables
probeVars[in.admsProbeID_V_A_GND] = (*solVectorPtr)[in.li_A];
probeVars[in.admsProbeID_V_A_K] = (*solVectorPtr)[in.li_A] - (*solVectorPtr)[in.li_K];



    // Need to use processParams-like function to process the
    // initial_model block with the LOCAL copies of
    //  model vars, and local copies of model
    // params.
evaluateInitialModel(
modelStruct,
 mod.admsModTemp,in.getDeviceOptions().gmin,in);
evaluateInitialInstance(
instanceStruct,
modelStruct,
in.admsTemperature, in.adms_vt_nom,in.getDeviceOptions().gmin,in);


// Now call  the function that does the heavy lifting.

evaluateModelEquations(
probeVars,
// probe constants
in.admsProbeID_V_A_GND,
in.admsProbeID_V_A_K,

// node constants
in.admsNodeID_A,
in.admsNodeID_K,
instanceStruct,
modelStruct,
 in.admsTemperature,
 in.adms_vt_nom,
 in.getDeviceOptions().gmin,
 d_staticContributions_dX,
 d_dynamicContributions_dX,
 in);


  // We now have the F and Q vector stuff, populate the dependencies:

    dfdp[in.admsNodeID_A+inst*(2+0)] += d_staticContributions_dX[in.admsNodeID_A];
    dqdp[in.admsNodeID_A+inst*(2+0)] += d_dynamicContributions_dX[in.admsNodeID_A];
    Findices[in.admsNodeID_A+inst*(2+0)] = in.li_A;
    Qindices[in.admsNodeID_A+inst*(2+0)] = in.li_A;
    dfdp[in.admsNodeID_K+inst*(2+0)] += d_staticContributions_dX[in.admsNodeID_K];
    dqdp[in.admsNodeID_K+inst*(2+0)] += d_dynamicContributions_dX[in.admsNodeID_K];
    Findices[in.admsNodeID_K+inst*(2+0)] = in.li_K;
    Qindices[in.admsNodeID_K+inst*(2+0)] = in.li_K;
}

}

#endif // Xyce_ADMS_SENSITIVITIES

} // namespace ADMSJUNCAP200
} // namespace Device
} // namespace Xyce
